Skip to content

Inconsistent rounding behavior in Round and RoundUp methods #390

@KyleAdultHub

Description

@KyleAdultHub

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions