-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Proposal] Add new overload to Math.Truncate #40456
Comments
I think you can now do this with Math.Round(3.4611, 2, MidpointRounding.ToZero); //3.46
Math.Round(-3.4611, 2, MidpointRounding.ToZero); //-3.46
Math.Round(3.4679, 2, MidpointRounding.ToZero); //3.46
Math.Round(-3.4679, 2, MidpointRounding.ToZero); //-3.46 |
Tagging subscribers to this area: @tannergooding, @pgovind |
Thanks. |
@VBAndCs That is true and the only reason why I know about |
To me, I do believe that those behaviours you've described already exists in |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
Background and Motivation
A common task is to truncate doubles to a specific places after the decimal point. There is no easy, fast and precise way to do this in Math class. Either we can round the number, or use this formula:
more discussion about this is here:
https://stackoverflow.com/questions/3143657/truncate-two-decimal-places-without-rounding
Proposed API
So, I suggest to add a new overloads to the Truncate method:
Math.Truncate(double number, int precision)
Math.Truncate(decimal number, int precision)
so it can achieve this goal with a fast and accurate way to give us the best performance.
Usage Examples
The text was updated successfully, but these errors were encountered: