Skip to content

x/text/number, x/text/message: number formatting order of magnitude error #31254

@leith1972

Description

@leith1972

What version of Go are you using (go version)?

$ go version
go version go1.12.1 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/leith/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/leith/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build707188231=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
        "fmt"
        "golang.org/x/text/message"
        "golang.org/x/text/number"
)

func main() {
        p := message.NewPrinter(message.MatchLanguage("en"))
        n1 := 1.99999
        n2 := 0.99999
        n3 := 999.9999
        fmt.Println(p.Sprintf("%v", number.Decimal(n1, number.Precision(4), number.NoSeparator())))
        fmt.Println(p.Sprintf("%v", number.Decimal(n2, number.Precision(4), number.NoSeparator())))
        fmt.Println(p.Sprintf("%v", number.Decimal(n3, number.Precision(4), number.NoSeparator())))
}

What did you expect to see?

2
1
1000

What did you see instead?

2
0.1
100

numbers such as 0.99999 are formatted an order of magnitude too small.

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions