Forum Moderators: open

Message Too Old, No Replies

Baffled by the results of this equation

int(30) = 29

         

TheDave

4:17 am on Jul 15, 2003 (gmt 0)

10+ Year Member



I'm using something similar to this in an asp page, why would it be spitting out 29 instead of 30? :/

This exact equation produces 29 for me - no variables:

int(((2.3 - 2)*100))

jomaxx

4:34 am on Jul 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In some cases, floating point arithmetic will represent the result as something like 29.999999 instead of precisely 30. Then when you do the int() function, it truncates it to 29.

If this is your problem, the solution is to add a bit before truncating - either 0.5, if that accuracy is satisfactory, or else a tiny amount that should be transparent to any user, such as .000002.

TheDave

5:52 am on Jul 15, 2003 (gmt 0)

10+ Year Member



Ahhh thanks! I'll add 0.0001 before converting