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

Consider adding support for unit when using math.round() #3086

Closed
mofosyne opened this issue Oct 27, 2023 · 2 comments
Closed

Consider adding support for unit when using math.round() #3086

mofosyne opened this issue Oct 27, 2023 · 2 comments

Comments

@mofosyne
Copy link

First example works as expected

math.round(math.evaluate("2.223"), 2).toString()
"2.22"

Second example doesn't work as expected

math.round(math.evaluate("2.223kg"), 2).toString() 
Uncaught TypeError: Unexpected type of argument in function round (expected: number or Complex or BigNumber or Fraction or Array or Matrix or DenseMatrix or SparseMatrix or string or boolean, actual: Unit, index: 0)

My desired behavior would be

math.round(math.evaluate("2.223kg"), 2).toString()
"2.22kg"

Possible challenges, is you will need to account for people doing strange units like "kg2.223" or "2.223kg^2", so addressing this will require parsing to properly capture the units.

@josdejong
Copy link
Owner

I think this is a duplicate of #2761, let's continue the discussion there.

@mofosyne
Copy link
Author

Ah missed that as I was only searching issue tickets. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants