Skip to content
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

RoundUp, RoundCeil, RoundDown etc do not rescale the number as Round does #333

Open
ckritzinger opened this issue Nov 3, 2023 · 1 comment

Comments

@ckritzinger
Copy link

x.Round(n) will rescale the number so that the coefficient contains exactly n digits

However x.RoundUp(n) and seemingly RoundCeil, RoundDown, etc do not exhibit the same behaviour.

amount, _ := decimal.NewFromString("0.01230000000000000000000000000000")
fmt.Printf("amount.RoundUp coefficient 64: %v\n", amount.RoundUp(4).CoefficientInt64())
fmt.Printf("amount.Round coefficient 64: %v\n", amount.Round(4).CoefficientInt64())

// amount.RoundUp coefficient 64: -2609795702905110528
// amount.Round coefficient 64: 123

Is this expected behaviour?

@mwoss
Copy link
Member

mwoss commented Dec 30, 2023

Thanks for the report! I'll take a look at that, but at first glance, it looks like an inconsistent behavior that should be fixed. :3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants