#390·decimal

Inconsistent rounding behavior in Round and RoundUp methods

Author: KyleAdultHubCreated Dec 27, 2024Updated Dec 27, 2024

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