PDA

View Full Version : Obj to convert integer to string and add decimal?

T Chap
12-20-2009, 09:27 AM
Is there an object that will convert a decimal to a string for LCD purposes as shown. There always needs to be 4 decimals even if 0's, but the integer doesn't contain any decimals. There are no resources for cogs for floating point. I was looking at the Numbers obj but haven't figured out it ToStr is the right thing to accomplish this.

714875 to "71.4875"

Thanks for any obj suggestions.

EDIT:

I worked out a simple trick to destruct the integer and construct the string:

int := (int * 10000) + (deci * 625)
int := ((int * 9) / 5) + 320_000
'go(1,0)
'ser.decf(3, int, 6)
'ser.str(3, string("F"))
go(1,0)
F := int/10000 ' extract the two digits to the left of the decimal
ser.dec(3, F) 'display the two left digits
ser.str(3, string(".")) 'display the decimal point
int := int - (F*10000) 'subtract the two left digits from the total and display the 4 digits to the right
ser.decf(3, int, 4)

Post Edited (Todd Chapman) : 12/20/2009 3:02:12 AM GMT

Mike Green
12-20-2009, 12:28 PM