Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

round function doesn't work as expected in Python #47

Open
ikaradogan opened this issue Oct 26, 2020 · 2 comments
Open

round function doesn't work as expected in Python #47

ikaradogan opened this issue Oct 26, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@ikaradogan
Copy link

The round function takes one or two parameters in Python and one parameter in JavaScript. In Flexx, while using round with two parameter in PyWidget, the program does not fail, but in JS Widget it fails.

        rounded1 = round(number)
        # works with one parameter as expected either in Python or JavaScript

        rounded2 = round(number, decimals)
        # doesn't work on JS Widget, but works in PyWidget

        rounded3 = number.toFixed(decimals)
        # as toFixed is a JavaScript method that formats a number, it works on JS Widget,
        # but with a non-negative parameter and it gives fixed decimal digits

From what i see this line may need to be fixed.

@almarklein
Copy link
Member

Thanks for the nice catch. I'm sure this is not the last discrepancy to be found :)

Yes, that line is where we could create a function instead of aliasing Math.round. I don't have much free cycles the coming weeks. A PR (by you, or anybody else) is welcome!

@almarklein almarklein added the bug Something isn't working label Nov 2, 2020
@pyxdroid
Copy link

Hi,
here is a short solution for stdlib.py.
greets
pyxdroid

FUNCTIONS['round'] = """function (x, dec) { // nargs: 1 2
return (x >= 0) ? (!dec ? Math.round(x) : Number(Math.round(x+'e'+dec)+'e-'+dec))
: (!dec ? Math.round(x-Number.EPSILON) : Number(Math.round(x-Number.EPSILON+'e'+dec)+'e-'+dec));
}"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants