Question : how to set 2 decimal places in java
Answered by : poised-polecat-oorg1f3djyrm
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
System.out.println(df.format(decimalNumber));
Source : https://stackoverflow.com/questions/2538787/how-to-print-a-float-with-2-decimal-places-in-java | Last Update : Wed, 12 Aug 20
Question : specify decimal places java
Answered by : bissallah-ahmed-ekele-jr
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 : https://www.baeldung.com/java-decimalformat | Last Update : Tue, 05 Jan 21
Question : how to check for a decimal point in java
Answered by : oliver-badger
d % 1 == 0
//THIS CHECKS IF VARIABLE D IS A WHOLE NUMBER
Source : https://stackoverflow.com/questions/15963895/how-to-check-if-a-double-value-has-no-decimal-part | Last Update : Mon, 26 Oct 20
Question : how to get 2 decimal places in java
Answered by : kushal
total = (double) 100 / listMember.size();
DecimalFormat df = new DecimalFormat("#.##");
String dx = df.format(total);
total = Double.valueOf(dx);
Source : | Last Update : Sat, 07 Aug 21
Question : java 2 decimals
Answered by : greedy-goblin
double res = Math.round(a * 100) / 100;
Source : | Last Update : Thu, 24 Dec 20