Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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

round decimals in java string

package com.mkyong.math.rounding;

public class StringFormatExample {

  public static void main(String[] args) {

      double input = 1205.6358;

      System.out.println("salary : " + input);

      // round half-up, no way control
      // 1205.64
      System.out.println("salary : " + String.format("%.2f", input));

      // 1205.64
      System.out.format("salary : %.2f", input);

  }

}
Comment

PREVIOUS NEXT
Code Example
Java :: how to change resource color to int color in android 
Java :: lcm of two large positive integers java 
Java :: java print a line seperate by space 
Java :: array reverse in java 
Java :: sorting methods in java 
Java :: maven skip make-assembly 
Java :: hide background of button java swing 
Java :: exit an if statement java 
Java :: how to use enumUtils in java 
Java :: add infinite numbers to variable java 
Java :: spring boot put invalid cors request 
Java :: windows Jmeter java.net.BindException: Address already in use: connect 
Java :: get SecretKey from String 
Java :: how to remove scroll pane border 
Java :: date to yyMMdd conversion 
Java :: enhance for loop java 
Java :: cannot find symbol iterator in java 
Java :: org.springframework.security.oauth2.jwt.JwtEncoder 
Java :: java border 
Java :: arraylist in java 
Java :: random int between two values 
Java :: transparent border of jtextfield in java 
Java :: creating jdbc connection in java using service name oracle 
Java :: java programme for fibonnaci series 
Java :: localbroadcastmanager android example 
Java :: intersection of two arrays java 
Java :: java developer interview questions 
Java :: string vs new string 
Java :: java add constructor to enum 
Java :: string into ascii in java 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =