Logo

Programming-Idioms

History of Idiom 65 > diff from v1 to v2

Edit summary for version 2 by :

Version 1

2015-04-21, 22:45:25

Version 2

2015-04-21, 22:58:18

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
import java.text.DecimalFormat;
Code
String s = new DecimalFormat("0.0%").format(x);
Comments bubble
This notation handles the multiplication by 100 for you.
Origin
http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html
Demo URL
https://ideone.com/acD3dm