This language bar is your friend. Select your favorite languages!
Edit summary for version 21 :
[Go] Fixed type litteral

Version 20

Version 21

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