In C# the following code returns 2:
double d = 2.9;
int i = (int)d;
Debug.WriteLine(i);
In Javascript, however, the only way of converting a "double" to an "int" that I'm aware of is by using Math.round/floor/toFixed etc. Is there a way of converting to an int in Javascript without rounding? I'm aware of the performance implications of Number() so I'd rather avoid converting it to a string if at all possible.
Math.floor
? – ManipurMath.floor
because it behaves different for negative numbers. CompareMath.floor(-2.5)
and-2.5|0
. – Confoundrounding towards zero.
– Clementeclementi