Answers for "how to round numbers in java"

2

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
Posted by: Guest on December-29-2020
5

how to round up in java

int x = 3.14;

Math.round(x);
//Rounds to nearest int
Math.ceil(x);
//Rounds up to int
Math.floor(x);
//Rounds down to int
Posted by: Guest on September-30-2020
0

rounding off in java

(double)Math.round(value * 100000d) / 100000d
Posted by: Guest on June-05-2021

Code answers related to "how to round numbers in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language