FUNCTION checkStrFloat(Str AS STRING) AS STRING ' trig by getItemDscr(1), c2Inventory(1) ' Search for a . in the string, then check if the string is longer than one character past the . and if so, trim off the rest
StrLen = Str.Len()
FOR i = 1 TO StrLen
chr = Str.Mid(i -1, 1) ' String.Mid() is 0 based, not 1 based, so need to -1
IF chr = "." ' Ex: "9.900001", i will be 2
IF StrLen > i +1 ' If there is more than just one character after the decimal point
StrNEW = Left(Str, i+1) ' Left() is 1 based ' Ex: i +1 will be 3, thus first three characters of "9.900001" will be "9.9", one character past the "."
? "checkStrFloat() found long float Str, orig " Str ", shortened " StrNew
RETURN StrNEW
END IF
END IF
END FOR
RETURN Str
END FUNCTION
function convert(f as double) as string
a = CInt(f * 10)
n = a \ 10
m = abs(a) mod 10
return n.toStr() + "." + m.toStr()
end function
"Komag" wrote:
Try this:
? 1.1* 9
console prints 9.9
But try this:
? str(1.1 * 9)
console prints 9.900001
x=1.1 * 9
' 1) use Fix to try to force 1 digit of precision. may or may not work?
? Str(Fix(x * 10)/10)
' 2) use printf-style conversion
? x.ToStr("%3.1f")
' Note that Str prefixes a blank on non-negative numbers, the above ToStr does not.
' if you want that, use x.ToStr("% 3.1f")
"renojim" wrote:
My advice is to only use integer math unless there's a compelling reason not to (which there never is).
? str(1.1*9)
9.900001
? (1.1*9).tostr()
9.9
FUNCTION washFloat(dirtyFloat)
Int10 = Cint(dirtyFloat *10)
cleanFloat = Int10 / 10
RETURN cleanFloat
END FUNCTION
"Komag" wrote:
And then I'll use float.ToStr() for double measure (unless there are Roku models or firmware on which that won't work?)