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 :: java reverse string 
Java :: code to include layout from java in android 
Java :: get all keys from pbject javascirpt 
Java :: spring boot access images in resources folder 
Java :: set solid color background android programatically in drawable 
Java :: restart java windows 
Java :: crear objetos automaticamente java 
Java :: android maven dependency 
Java :: android textview center align text programmatically 
Java :: for cicle java 
Java :: how to copy array in java 
Java :: how to split string in java android 
Java :: volley android 
Java :: java initialize class 
Java :: convert void * to int 
Java :: declaration and definition of array in java 
Java :: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.5.0:repackage failed: 
Java :: generate uuid from string 
Java :: how to add spaces before string in java 
Java :: JsonArray get first Object 
Java :: override class java 
Java :: jdk 15 download brew 
Java :: print in java 
Java :: create a hashmap 
Java :: java concatenate strings 
Java :: comparacion de strings java 
Java :: static class java 
Java :: add int to list java 
Java :: dockerfile for spring boot app 
Java :: How to return the elements of a matrix in spiral order, in Java? 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =