Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

specify decimal places java

double test = 12.15;
DecimalFormat df = new DecimalFormat("#.0");
System.out.println(df.format(test)); // Console: 12.2
// # - prints a digit if provided, nothing otherwise
// . - indicates where to put the decimal seperator
// 0 - prints a digit if provided, 0 otherwise
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #decimal #places #java
ADD COMMENT
Topic
Name
1+7 =