diff --git a/src/js2python.c b/src/js2python.c index bb81a0f67..2788a8b0c 100644 --- a/src/js2python.c +++ b/src/js2python.c @@ -23,6 +23,11 @@ _js2python_get_ptr(int obj) int _js2python_number(double val) { + double i; + + if (modf(val, &i) == 0.0) + return (int)PyLong_FromDouble(i); + return (int)PyFloat_FromDouble(val); } diff --git a/test/test_python.py b/test/test_python.py index ac951ffd9..83ce6d596 100644 --- a/test/test_python.py +++ b/test/test_python.py @@ -224,10 +224,10 @@ def test_js2python(selenium): 'jsstring_ucs4 == "🐍"') assert selenium.run( 'from js import jsnumber0\n' - 'jsnumber0 == 42') + 'jsnumber0 == 42 and isinstance(jsnumber0, int)') assert selenium.run( 'from js import jsnumber1\n' - 'jsnumber1 == 42.5') + 'jsnumber1 == 42.5 and isinstance(jsnumber1, float)') assert selenium.run( 'from js import jsundefined\n' 'jsundefined is None')