The problem with using FormatNumber in that way is that it doesn't assign the variable the type double, but formats it for viewing only and changes it to a string.
$i = FormatNumber("25,4") returns the string "25.00". As to how this result is obtained, I'm not sure, but it can't be used as a number again unless you do
$i = VAL($i)
....
$i = FormatNumber(25,4) returns the string
"25.0000"
So, FormatNumber does NOT work like a TRUNCATE function would work.
Example:
code:
; $v=Voltage $i=Current $r=Resistance
$v=CDBL(25)
$i=CDBL(2)
$r=FormatNumber($v/$i)
? "Voltage is: " FormatNumber($v,4)
? "Current is: " FormatNumber($i,4)
? "Resistance is: " FormatNumber($r,4) + " Ohms "
; Result = 25.0000 which is the wrong value
$v=CDBL(25)
$i=CDBL(2)
$r=$v/$i
? "Voltage is: " $v
? "Current is: " $i
? "Resistance is: " $r + " Ohms " ?
; Result = 12 which is the wrong value
This should return proper values. In this case only the first variable evaluated in an expression need be type CDBL, but i put it in anyway to avoid confusion.
Brian