trunc(?)
Sarah Reichelt
sarah.reichelt at gmail.com
Fri Jan 22 17:49:00 EST 2010
> But I cavalierly thought that trunc would work too. It does not. Even
> though the docs say that trunc returns an integer, it does not when the
> numberFormat is in play:
>
> on mouseUp
> set numberformat to "#.00"
> put 1 into y
> add 0 to y
> answer trunc(y) -- yields "1.00"
> end mouseUp
>
> Neither does the "round" function.
It seems that the numberFormat is taking precedence here.
If you try this in the message box:
put trunc(1.00)
or
put round(1.00)
you will get 1 as expected, but in your sample, the y is being
truncated, then the 2 decimal places are being re-applied for the
answer. You can check that this is what is happening by setting y to
something like 1.23, which makes your "answer" display 1.00
As a general rule, I much prefer using the format function to the
numberFormat. I feel that I have more control that way, since it is
only applied to numbers that I want to apply it to, instead of all
numbers which is what causes problems like the one with the field
reference.
Cheers,
Sarah
More information about the use-livecode
mailing list