constant lenght of decimal
I`m new to propeller, so i`m sorry for a noob question, but I have searched through the forum and can`t find the answer, though I`m sure it`s there...
I`m sending a string using full duplex serial object, and it works fine, but I want the string to be constant lenght. In bs2 i just put DEC3 for 3 digits, but how to do it in spin?
example from my code:
serial.dec(compass.heading)
I`m sending a string using full duplex serial object, and it works fine, but I want the string to be constant lenght. In bs2 i just put DEC3 for 3 digits, but how to do it in spin?
example from my code:
serial.dec(compass.heading)

Comments
PUB decn(value, digits) | mindigits, val '' Print a decimal number, right-justified in a field width given by ||digits. '' If digits < 0, pad with leading zeroes; otherwise, pad with leading blanks. mindigits := ((value < 0) & 1) + 1 if (value <> $8000_0000) val := || value repeat while (val /= 10) mindigits++ if (value < 0 and digits < 0) tx("-") value := ||value repeat (||digits - mindigits) #> 0 if (digits < 0) tx("0") else tx(" ") dec(value)-PhilPUB decFixed(value,width,numPlaces) | i, j, p, f, a, b, c, d '' Print a decimal number of fixed width with decimal places numPlaces #>= 0 numPlaces <#= 10 p := @a f~ if value < 0 -value byte[p++] := "-" i := 1_000_000_000 repeat j from 1 to 10 - numPlaces if value => i byte[p++] := value / i + "0" value //= i f~~ elseif f or j == (10 - numPlaces) byte[p++] := "0" i /= 10 if numPlaces byte[p++] := "." repeat numPlaces if value => i byte[p++] := value / i + "0" value //= i else byte[p++] := "0" i /= 10 byte[p]~ i := strsize(@a) if i < width repeat width - i out(" ") str(@a)http://obex.parallax.com/objects/182/
This one is overkill and sometimes not as immediate
http://obex.parallax.com/objects/23/
Massimo
-Phil