0
JS math.ceil
Hello, why the code below returns 218, not 217? Math.ceil(195.3/(75/1000)*12))
2 Answers
+ 4
The result of your formula is 31249.
You can understand it better if you print the intermediary results.
In Javascript a division gives you a floating point number.
And calculating with floats, will always be a little imprecise, because they cannot always be correctly represented in a finite number of bits in memory.
Math.ceil will round up the result to the next integer, even when the fractional part is just a tiny, tiny number.
https://code.sololearn.com/c1usD4kx4rbT/?ref=app
+ 2
Thanks Tibor for answer.
I missed one bracket 195.3/((75/1000)*12).
However, from mathematical point of view x1 and x11 in my code supposed to be equalâŠ
https://code.sololearn.com/czOh5LQKO5xe/?ref=app
I need to take that imprecision into account.