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

Inconsistent rounding behavior in Round and RoundUp methods #390

Open
KyleAdultHub opened this issue Dec 27, 2024 · 0 comments
Open

Inconsistent rounding behavior in Round and RoundUp methods #390

KyleAdultHub opened this issue Dec 27, 2024 · 0 comments

Comments

@KyleAdultHub
Copy link

When using the RoundUp(0) method, the results are inconsistent with the Round method. Below are example cases demonstrating the issue:

`
func ExampleNewBigDecimal() {

d1, _ := decimal.NewFromString("100.0")
d1 = d1.Round(0)
fmt.Println(d1.StringFixedBank(-d1.Exponent())) // amount to 100

d2, _ := decimal.NewFromString("100.0")
d2 = d2.RoundUp(0)                              // or RoundDown、RoundFloor...
fmt.Println(d2.StringFixedBank(-d2.Exponent())) // amount to 100.0

//Output:
// 100
// 100

}
`

output
got: 100 100.0

the reason is RoundUp method would return the original input, when rescaled equal input decimal, The code location is shown in the figure
image

@KyleAdultHub KyleAdultHub changed the title Inconsistent rounding behavior in RoundUp and RoundDown methods Inconsistent rounding behavior in Round and RoundUp methods Dec 27, 2024
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

1 participant