Quote: "I'm reading values from an ini file, so I have saved all values as value * 100, then I divide by 100 when I read it back in."
Do you lose any accuracy with that (on certain numbers anyway e.g 123.45)?
I quickly wrote a function to convert strings to decimals for fun but I loose accuracy when I divide.
rem A Wizard Did It!
val1$ = "1.234"
val2$ = "4.35"
Val3$ = "123.45"
dec1# = getDecimalVal(val1$)
dec2# = getDecimalVal(val2$)
dec3# = getDecimalVal(val3$)
b# = 12345.0 / 100.0
do
Print(val1$ + " : " + str(dec1#))
Print(val2$ + " : " + str(dec2#))
Print(val3$ + " : " + str(dec3#))
print(b#)
Sync()
loop
function getDecimalVal( decimal$ as string )
// locals
length as integer = 0 // length of string
place as integer = 0 // the place of the current character when looping through the string
p10 as integer = 0 // power of 10
value# as float = 0.0 // the decimal to be returned
intvalue as float = 0.0 // the integer half of the value e.g 123 is the intvalue in 123.45
decvalue as float = 0.0 // the complement of intvalue e.g 45 is the decvalue in 123.45
// get the length of the decimal
length = len(decimal$)
// loop through until we find the decimal point
repeat
place = place + 1
until mid(decimal$, place, 1) = "." or place > length
p10 = length - place // get the power of 10 we will need to multipy by and divide by
intvalue = val( left( decimal$, place-1)) // get the value for intvalue
decvalue = val( right( decimal$, p10)) // get the decimal value in integer form
// multiply by the power of 10, add the decimal and then divide by the power of 10
value# = ((intvalue * (10.0^p10)) + decvalue) / (10.0^p10)
endfunction value# // return decimal.
It may just be the general loss of accuracy though which many languages suffer from so there's probably no point trying to fix the above.
Quote: "[EDIT] - fixed in V107"
Good to hear.