Logo

Programming-Idioms

History of Idiom 65 > diff from v21 to v22

Edit summary for version 22 by programming-idioms.org:
[Go] +DocURL

Version 21

2016-05-28, 09:31:56

Version 22

2016-05-28, 09:32:52

Idiom #65 Format decimal number

From real value x in [0,1], create its percentage string representation s with one digit after decimal point. E.g. 0.15625 -> "15.6%"

Idiom #65 Format decimal number

From real value x in [0,1], create its percentage string representation s with one digit after decimal point. E.g. 0.15625 -> "15.6%"

Extra Keywords
percent
Extra Keywords
percent
Imports
import "fmt"
Imports
import "fmt"
Code
s := fmt.Sprintf("%.1f%%", 100.0*x)
Code
s := fmt.Sprintf("%.1f%%", 100.0*x)
Comments bubble
The literal % must be doubled.
Comments bubble
The literal % must be doubled.
Doc URL
https://golang.org/pkg/fmt/
Demo URL
https://play.golang.org/p/QVtaV89w2E
Demo URL
https://play.golang.org/p/QVtaV89w2E