Logo

Programming-Idioms

History of Idiom 65 > diff from v2 to v3

Edit summary for version 3 by :

Version 2

2015-04-21, 22:58:18

Version 3

2015-04-21, 22:59:50

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%"

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