Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java round double to 2 decimals

double roundOff = Math.round(a * 100.0) / 100.0;
// Or
double roundOff = (double) Math.round(a * 100) / 100;
// both have the same output.
Comment

round off java 2 decimal places

class round{
    public static void main(String args[]){

    double a = 123.13698;
    double roundOff = Math.round(a*100)/100;

    System.out.println(roundOff);
}
}
Comment

how to round double to 2 decimal places java

// 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();
}
Comment

round the value of 2 decimals in java

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);
}
}
Comment

PREVIOUS NEXT
Code Example
Java :: change color of jframe 
Java :: Java Copying Arrays Using copyOfRange() method 
Java :: android fragment fullscreen 
Java :: how to create a random number in java 
Java :: java.lang.ExceptionInInitializerError: null 
Java :: android studio textview set text int 
Java :: java biginteger multiply 
Java :: java get number of days in month 
Java :: resource leak java 
Java :: javafx object rectangle 
Java :: mockito verify not called 
Java :: console printing in java 
Java :: get text from edittext android 
Java :: worldedit set random blocks 
Java :: java system.out.print two dimensional array 
Java :: turning a sentence to an array java 
Java :: space in java 
Java :: kill all java processes linux 
Java :: lombok gradle dependency spring boot 
Java :: sum of 1D array(JAVA) 
Java :: java prime numbers 
Java :: do while loop in java 
Java :: how to get multiple integer input in java 
Java :: java filenotfoundexception 
Java :: android create snackbar 
Java :: jbutton set on action 
Java :: check if string contains only letters java 
Java :: Java Scanner nextLine() 
Java :: java tomorrow date 
Java :: java sealed class 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =