Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

number format java


double r = 5.1234;
System.out.println(r); // r is 5.1234

int decimalPlaces = 2;
BigDecimal bd = new BigDecimal(r);

// setScale is immutable
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
r = bd.doubleValue();

System.out.println(r); // r is 5.12

Source by devarama.com #
 
PREVIOUS NEXT
Tagged: #number #format #java
ADD COMMENT
Topic
Name
7+9 =