Logo

Programming-Idioms

History of Idiom 65 > diff from v10 to v11

Edit summary for version 11 by :

Version 10

2015-08-21, 14:59:59

Version 11

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