Skip to content

strconv: FormatFloat(x, 'g', -1, 64) does not give the most precise decimal approximation #2625

@remyoudompheng

Description

@remyoudompheng
What steps will reproduce the problem?
1. compile and run

package main

import "strconv"
import "fmt"

func main() {
    fmt.Println(strconv.FormatFloat(383260575764816448, 'g', -1, 64))
}


What is the expected output?

3.8326057576481645e+17

What do you see instead?

3.8326057576481644e+17

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

linux

Which revision are you using?  (hg identify)

c956aa39a269 (tip)

Please provide any additional information below.

The obtained result has the same length and can be parsed to the same float64 as the
expected result. However, it is not the closest possible to the original float
(5988446496325257p+6).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions