-
Notifications
You must be signed in to change notification settings - Fork 627
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
Revert remove insignificant digits #159
Conversation
Currently, there is a bug in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, ready to merge :3
Thanks for maintaining this library 💪 ! A quick question regarding this PR: Is it correct that when using And the correct way to compare them would be to either use |
Hi @philippgille. I apologize for the late response, I had a tough weekend. |
For creating a snippet I had another look and the root cause seems to be that the initial decimal is created with So in the end I'd say this library behaves correctly and as expected (8 decimal places in the DB lead to 8 decimal places in the deserialized field). It's just a breaking or at least noteworthy change. |
@philippgille Yes, if those decimals differ by two last zeroes after a comma, they for sure, should not be equal. This was discussed in depth in #107. |
Does it make sense to add a note to the README or so, because the behavior was different for almost exactly 3 years, so I can imagine other people updating the package and wondering about failing unit tests as well :) |
I'm 100% agreeing with you. I'm adding this task to our backlog. |
* revert original remove insignificant change (PR 46), and add the logic back as a function
I could not find the backlog issue so pardon me for reviving this zombie thread 😄 |
We just got burned by this breaking change after upgrading the package. func getOldExponent(x decimal.Decimal) int32 {
return decimal.RequireFromString(x.String()).Exponent()
} Is there a better way? @mwoss (p.s thank you for this library). |
I deeply apologize for my late reply! I was not actively maintaining this library in the past year :< @daemonfire300 - Sure I will take a look at your PR @tzachshabtay - I apologize for that. We should've communicated this change more broadly or introduced it in the 2.x release. Right now library does not provide an easy way to calculate precision ignoring trailing zeroes. You can do it your way or count the trailing zeroes and substract it from func getPrecisionWithoutTrailingZeroes(d Decimal) int32 {
coeff := d.Coefficient().String()
trailingZeroes := len(coeff) - len(strings.TrimRight(coeff, "0"))
return min(0, d.Exponent()+int32(trailingZeroes)) // for positive exponents decimal precision is always 0
} |
When I went to revert #46,
TestDecimal_RoundCash
started failing because theRoundCash
function (#66) relies on a Decimal with insignificant digits removed. To get around this problem I made a new function to remove insignificant digits