Shop OBEX P1 Docs P2 Docs Learn Events
FloatString is haunting me again. Help or sugjestion.. — Parallax Forums

FloatString is haunting me again. Help or sugjestion..

grasshoppergrasshopper Posts: 438
edited 2008-12-12 18:27 in Propeller 1
I am trying to conjure up some type of method that can handle the "width" in FloatToFormat listed in the FloatString object. My problem is that I am sending data Via the FullDuplexSerial object like below and the structure of the data being sent is not the consistency I must have.

 ser.str(string("Current - "))         
 ser.str(strings.FloatToFormat(Data,8,4))
 ser.str(String(" C"))




This is fine as long as my number is 100.00. The problem is when my number changes to 50.23 then there is a space before the 5.

Like this

Current - 100.00 C
Current -  50.23 C




I am trying to get this

Current - 100.00 C
Current - 50.23 C




So far I have tryed to write methods to calculate the necessary number for X in --> ser.str(strings.FloatToFormat(Data,X,4)) But no luck so far.

Any ideas ?

Comments

  • JetfireJetfire Posts: 34
    edited 2008-12-11 19:05
    In the notes for FloatToFormat it says:
    "'' leading blank fill is used"

    At this bottom is this code:

        ' leading blank fill
        repeat while p <> stringptr
          byte[noparse][[/noparse]--p] := " "
    
    



    Try commenting them out.
  • grasshoppergrasshopper Posts: 438
    edited 2008-12-11 19:33
    No that did not work, It just moved the decimal place over to the right.
  • JetfireJetfire Posts: 34
    edited 2008-12-11 20:46
    Try this code:

        ' leading blank fill
        repeat while p <> stringptr
          ++stringptr
    
    
  • grasshoppergrasshopper Posts: 438
    edited 2008-12-12 01:18
    Hum ill have to give this a try tomorrow. Thanks for the help so far.
  • grasshoppergrasshopper Posts: 438
    edited 2008-12-12 18:27
    Yulp This solved the problem. Thanks again.
Sign In or Register to comment.