-
Notifications
You must be signed in to change notification settings - Fork 169
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
Redefine rescale
as rescale_mut
and introduce an inline rescale
function
#391
Comments
Hi @cksac , Thank you for the question: short answer is yes, it is expected behavior at the moment. I'll try to explain: For the first example ( In the second example ( I wanted to check other libraries and see that the logic behind this closely mirrors .NET decimal behavior (e.g. https://dotnetfiddle.net/QY5ub3). That doesn't mean all that much except that we're being consistent in handling behavior like this. I do think that it could be considered confusing if you're expecting Regardless, I'm going to keep this issue open. I do think this warrants some further documentation to clearly explain behavior such as this as well as suggested "workarounds" (in lieu of explicit functions). |
Thanks for detail explanation. I think introduce another rounding function to guarantee the scale would be nice. |
Hi @cksac - just thinking about it... would |
Hi @paupino, thanks for suggestion. impl DecimalExt for Decimal {
fn truncate_p(&self, precision: u32) -> Self {
let mut p = self.round_dp_with_strategy(precision, RoundingStrategy::ToZero);
p.rescale(precision);
p
}
fn floor_p(&self, precision: u32) -> Self {
let mut p = self.round_dp_with_strategy(precision, RoundingStrategy::ToNegativeInfinity);
p.rescale(precision);
p
}
fn ceil_p(&self, precision: u32) -> Self {
let mut p = self.round_dp_with_strategy(precision, RoundingStrategy::ToPositiveInfinity);
p.rescale(precision);
p
}
} |
I think the action for this ticket is to implement an inline
My concern with the |
rescale
as rescale_mut
and introduce an inline rescale
function
This only ever happens when printing the actual result, and Rust has different formatting rules on displaying arbitrary-length decimal digits (i.e. stopping at the last infinite stream of zeros) vs. displaying specified-precision decimal digits (i.e. always displays the same number of digits). In Rust, if no specific formatting flag is specified, the standard display style is arbitrary-length format, so I suggest we should just mirror that. If you think about it, the integral part of the number also does not, by default, have leading zeros to indicate precision (but there is also a formatting flag to add the zeros). So it is consistent. |
Until this is implemented, |
Is below expected?
output
The text was updated successfully, but these errors were encountered: