Skip to content

math/big: Float.String inconsistent with format %v #42887

@rogpeppe

Description

@rogpeppe

go version devel +926994fd7c Thu Nov 26 21:10:09 2020 +0000 linux/amd64

I was surprised today when I discovered that big.Float.String truncates to 10 decimal digits of precision, which is surely not a very useful default for a "big" float. I would expect the result to use as many digits of precision as necessary, as if it was using Float.Text('g', -1).

Another remark: most types that implement fmt.Stringer work with the %s verb. Perhaps big.Float could do that too, making %s equivalent to %v.

The following code prints three different things. I'd expect it to print the same thing three times:

x := big.NewFloat(4.2949672961e+09)

fmt.Printf("%v\n", x)
fmt.Printf("%s\n", x.String())
fmt.Printf("%s\n", x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions