Logo

Programming-Idioms

History of Idiom 65 > diff from v20 to v21

Edit summary for version 21 by programming-idioms.org:
[Go] Fixed type litteral

Version 20

2016-05-10, 13:32:57

Version 21

2016-05-28, 09:31:56

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 litteral % must be doubled.
Comments bubble
The literal % must be doubled.
Demo URL
https://play.golang.org/p/QVtaV89w2E
Demo URL
https://play.golang.org/p/QVtaV89w2E