Strange math behaviour... could someone explain this ?

Mark Waddingham 36degrees at
Sun Oct 9 09:52:13 EDT 2005

Hi JB,

>   get ((36-34.2)*100)
>   put it & cr & trunc(it)

Revolution has a 'numberFormat' property that determines to how many
decimal places are used when numbers are converted to a string.

The difference you are observing here is that the first line is the
string representation of 'it' to (IIRC) 6 decimal places and the second
line is the string representation of trunc(it) to 6 decimal places.

As 'it' contains the number:  
When rounded to 6 decimal places you get 180

However, trunc(it) contains 179 and so is just 179 when rounded to 6
decimal places.

If you do:
  set the numberFormat to ".###############"
  get ((36-34.2)*100)
  put it & return & trunc(it)

You get:

Which is more inline with what you see in Javascript.

Warmest Regards,


 Mark Waddingham ~ 36degrees at ~
       Runtime Revolution ~ User-Centric Development Tools

More information about the Use-livecode mailing list