-
Notifications
You must be signed in to change notification settings - Fork 73
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
Support for specifying max number of decimals #124
Comments
There's a bunch of work-in-progress branches for adding "Context support" to the arithmetic operations, but they're taking a while. // keep operation results to 25 digits
let ctx = Context::new().with_precision(25).unwrap();
let c = ctx.add(a, b);
let z = ctx.mul(x, y); Is that what you're looking for? Until those are done you'll have to use the |
@akubera thanks for the response. I actually specifically need to set the scale, not the precision. I have a fork where I did some work on that, and it works for divisions but it's failing for multiplications so I need to finish the implementation. Happy to open a PR if it's something that you would be open to merging eventually. |
Well in that case I wonder what you think about adding the ability to use precision or a fixed (max) scale in the Context. Right now it's just the total precision pub struct Context {
/// total number of digits
precision: NonZeroU64,
/// how to round
rounding: RoundingMode,
} But we could do something like: enum DigitLimiter {
/// total number of digits
Precision(NonZeroU64),
/// Max number of digits after the decimal point
MaxScale(i64),
}
pub struct Context {
/// total number of digits
digit_limit: DigitLimiter,
/// how to round
rounding: RoundingMode,
} |
My use case requires a maximum number of decimals for all numbers.
I am not aware of a setting to enforce that globally at the moment, so the only way to achieve that is to always call
.with_scale(x)
after every operation which is very verbose and error-prone.The text was updated successfully, but these errors were encountered: