Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

How to round up to 2 decimal places in java?

Asked by Camellia Kleiber Apr 6, 2021 732 views 1 answer
Share

About this question

I am using math.round() to round off. this is the code:

class round{

    public static void main(String args[]){

    double a = 123.13698;

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

    System.out.println(roundOff);

}

}

the output I get is 123 but I want it to be 123.14. 

How to implement code to get the java roundup double and obtained desired output? 

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.