Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

JS math func error

Open Fretice opened this issue 6 years ago • 1 comments

when i run eval("Math.round(.5) + ~~1.8") in JS Console , the result is 2

but when i run in Python Console, the result is 1

Fretice avatar Jul 04 '19 08:07 Fretice

Had the same issue with Math.round(52.5).


https://docs.python.org/3/library/functions.html#round

rounding is done toward the even choice

https://github.com/PiotrDabkowski/Js2Py/blob/2e017b86e2f18a6c8a842293b1687f2ce7baa12e/js2py/constructors/jsmath.py#L83


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round

If the fractional portion is exactly 0.5, the argument is rounded to the next integer in the direction of +∞.

oliverpool avatar Oct 07 '25 14:10 oliverpool