-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Flesh out Decimal API and allow rounding to negative decimal places #33126
Comments
What does it mean to be a canonical decimal? |
|
The
With that, at least item 2 from the original post wouldn't be applicable to |
Sorry I've been slow about this. Allow rounding to negative decimal places: #35464 |
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. |
The
Decimal
API (taken here to includeSystem.Double
API where this includes decimal representations) is rather thin and needs rounding out.Rounding to negative decimal places:
Decimal.Round(_,digits:int)
andMath.Round(_,digits:int)
should allowdigits
to be negative.For example
Decimal.Round(123M,-1)
should give120M
.Creating a Decimal from components, and getting the components of a Decimal:
Decimal.FromComponents(positive:bool,exponent:int,significand:Decimal)
andDecimal.Exponent(d:Decimal)
andDecimal.Significand()
.Decimal.Pow(d:Decimal, exponent:int)
At the moment multiplying a decimal by 10^n, an extremely simple operation, is very hard.
See https://developer.apple.com/documentation/foundation/decimal for Swift's more complete API.
Related: a normalization method has been suggested here.
The text was updated successfully, but these errors were encountered: