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

double round java integer

int a = (int) Math.round(doubleVar);
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 :: primefaces datepicker validation 
Java :: assert system.out.println 
Java :: how to change top of window in java 
Java :: how to play audio files java 
Java :: java check if directory exists 
Java :: use view binding in fragment 
Java :: java button 
Java :: list extension quarkus 
Java :: convert hashset to array 
Java :: java float get 2 decimals 
Java :: creating modulu function withou using % java 
Java :: how to declare list of object in java as constant 
Java :: android send parameters with intent 
Java :: kotlin textview center text 
Java :: how to make a char uppercase in java 
Java :: java convert list to page 
Java :: Copying Arrays Using copyOfRange() method Java 
Java :: android java convert double to 2 decimal places 
Java :: java set label color 
Java :: print to console in java 
Java :: what is import java.io.*? 
Java :: how to destroy activity in android 
Java :: java parallel sort 
Java :: java version 
Java :: java negative infinity 
Java :: java stream sum integers 
Java :: print * pattern in java 
Java :: binary to integer in java 
Java :: java map not null 
Java :: make window visible java 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =