Question : java round double to 2 decimals
Answered by : zwazel
double roundOff = Math.round(a * 100.0) / 100.0;
// Or
double roundOff = (double) Math.round(a * 100) / 100;
// both have the same output.
Source : https://stackoverflow.com/a/11701527/12287687 | Last Update : Tue, 28 Sep 21
Question : round off java 2 decimal places
Answered by : amused-albatross-a1fatbl3rji4
class round{ public static void main(String args[]){ double a = 123.13698; double roundOff = Math.round(a*100)/100; System.out.println(roundOff);
}
}
Source : https://stackoverflow.com/questions/11701399/round-up-to-2-decimal-places-in-java | Last Update : Tue, 13 Oct 20
Question : round java 2 decimals
Answered by : dineth-s
{"tags":[{"tag":"textarea","content":"DecimalFormat df = new DecimalFormat(\"#.##\");\ndf.format(55.544545);","code_language":"java"}]}
Source : | Last Update : Sat, 25 Feb 23
Question : how to round double to 2 decimal places java
Answered by : vishal-patel
// calling the function round
round(200.3456, 2);
// Include this function in your class
public static double round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); BigDecimal bd = BigDecimal.valueOf(value); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue();
}
Source : | Last Update : Thu, 28 Oct 21
Question : how to round a double into two decimal places in java
Answered by : ori-attal
double notRoundNum = 231.12321
DecimalFormat df = new DecimalFormat("#.##", new DecimalFormatSymbols(Locale.ENGLISH));
// (#.## sets the number of decimal places)
// (Decimals format symbols sets '.' as the symbol for decimals, if it's not defined like that as default)
double roundNum = Double.parseDouble(df.format(notRoundNum)); // = 123.12
Source : | Last Update : Mon, 26 Dec 22
Question : round the value of 2 decimals in java
Answered by : luis-marquez-mbru2wln86dj
class round{ public static void main(String args[]){ double a = 123.13698; double roundOff = Math.round(a*100)/100; //put attention to the parenthesis. System.out.println(roundOff);
}
}
Source : https://www.codegrepper.com/search.php?q=round%20the%20value%20upto%202%20decimal%20in%20java | Last Update : Sun, 29 May 22