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
regression: BigDecimal::from_str
gives unexpected result
#127
Comments
Ok, I'll look into this. |
The call to "normalized" removes all trailing zeros, so the 10 (structurally Version 0.4.3 changed the formatting in a way many people didn't like, so I'm changing formatting again for 0.4.4. We can look at solutions for this once that is out. |
I'm coming around to the idea of sane defaults meaning minimizing surprise and just print numbers that makes the most sense to humans. If user wants it to accurately express significant figures, that's what the scientific notation is for. The question then shifts to: what's sensible? I'm already using the compile-time environment variable I could use it or make another such that numbers with exponentials over threshold jump to exponential form. Looks like this number is 15 for Python.
|
sounds good, what will happen if the number is without floating point? lets say I have an array
|
I'm not sure what you mean by array. I don't think there's a way to do formatting for arrays and vecs automatically. But let's print some running sums: let strs = ["10", "10.1", "100.100"];
let mut x = BigDecimal::from(0);
for s in strs {
x += BigDeicmal::from_str(s).unwrap();
println!("{x}");
} I'd expect to print
and same if the numbers were in scientific notation: |
Thanks @akubera that looks great, looking forward for the release |
Made some examples of formats Decimal on left, f64 on right, formatted with format string on top
There's a little more work to do. |
@akubera any updates ? |
Please find a small test case which reflects the concern
in 0.4.1
it works as expected
in 0.4.3
BigDecimal::from_str
createsBigDecimal("10e0")
instead ofBigDecimal("10")
and now test failed because output is in exp formatThe text was updated successfully, but these errors were encountered: