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

Add support for MidpointRounding on Math.Round #2389

Closed
sWW26 opened this issue Feb 18, 2021 · 3 comments
Closed

Add support for MidpointRounding on Math.Round #2389

sWW26 opened this issue Feb 18, 2021 · 3 comments

Comments

@sWW26
Copy link

sWW26 commented Feb 18, 2021

Description

It would be good to be able to use the MidpointRounding option with Math.Round. It looks like big.js supports it & I think its the default for Math.round in JS too?

Repro code

https://fable.io/repl3/#?code=PYBwpgdgBAygngZwC5gLYFgBQWA2YlQAmYAxgJaoCGOASmAgK44EC8UAspUgBYB0NwBhEIAKAEy8ArOwA0UAAxz2ZQiGBkISAUMIaA5rwCCAd0pwAYgCdgqAFphrASigB6F1ATdBOQlABGYFAAzHJ6ZABu9FBiuPhQAGY4wFx0jMxQbJw8-ILC4lJyihwqahpauboQBiZmVjb2Tq7unt6+AcGhEVExmABC1sYIDrwAIja8JMAQCMB4vEl6RKQU1KlMSFj9wIPDY6gTUzNzCwlJKfTrQA&html=Q&css=Q

Expected and actual results

Math.Round(1.5M, 0, MidpointRounding.AwayFromZero) = 2
Math.Round(1.5, 0, MidpointRounding.AwayFromZero) = 2
Math.Round(2.5M, 0, MidpointRounding.AwayFromZero) = 3
Math.Round(2.5, 0, MidpointRounding.AwayFromZero) = 3

@alfonsogarciacaro
Copy link
Member

Hi @sWW26! Sorry for the late reply, I had a quick look at this and although it looks easy to solve, there are different things we need to do for proper support: deal with different overloads, MidpointRounding enum also has other cases, I couldn't find a "recommended" way to do half-up rounding in JS... so it may take some time. Of course any help to fix this is welcome!

@sWW26
Copy link
Author

sWW26 commented Mar 15, 2021

After a bit of research into the other MidpointRounding options it seems some of them are not very intuitive, as in they're nothing to do with midpoint logic at all 😕 which probably makes things even worse! see: dotnet/runtime#38160 .

@alfonsogarciacaro
Copy link
Member

Closing for now as the solution to this is not trivial. Please reopen if someone wants to work on this.

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

No branches or pull requests

2 participants