Skip to content

Incorrect string formatting when rounding up to include additional digit #178

Open
@jstol

Description

@jstol

I've run into some strange behaviour when converting values to strings that require rounding up. For example, see the code snippet below:

var b decimal.Big
b.SetString("9.996208266660")
fmt.Println(fmt.Sprintf("%.2f", &b)) // Should be 10.00, but is 1.000

b.SetString("0.9996208266660")
fmt.Println(fmt.Sprintf("%.2f", &b)) // Should be 1.00, but is 0.100

Other values appear to be fine – this appears to only happen when rounding up to include an additional digit, almost as if the decimal point is being outputted 1 position left from where it should be. Any idea why this may be happening? More examples can be found here. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions