How to round up a value to 2 decimal places?

0 votes
How to round up a value to 2 digit decimal value?
May 10, 2018 in Java by Daisy
• 8,050 points
77 views

2 answers to this question.

0 votes
double a=324.23456
double value = Math.round(a * 100.0) / 100.0;


Output will be: 324.23

answered May 10, 2018 by parth295
• 4,640 points
0 votes
double d = 2.34568;
DecimalFormat f = new DecimalFormat("##.00");
System.out.println(f.format(d));
answered Aug 30, 2018 by Sushmita
• 6,880 points

Related Questions In Java

0 votes
2 answers

How to round a double to 2 decimal places?

double value = 200.3456; System.out.printf("Value: %.2f", value); You can ...READ MORE

answered Dec 11, 2018 in Java by Sushmita
• 6,880 points
946 views
0 votes
2 answers

How to create a 2-D array in java?

int[][] multi = new int[5][]; multi[0] = new ...READ MORE

answered Jul 16, 2018 in Java by Daisy
• 8,050 points
62 views
0 votes
2 answers

How can we display an output of float data with 2 decimal places in java? Please help

Use String.format()  if you need the value as ...READ MORE

answered Aug 26 in Java by Sirajul
• 40,980 points
62 views
0 votes
1 answer

How can we format float to n decimal places ?

You may pass the float value: String.format("%.2f", floatVal); READ MORE

answered Jul 2, 2018 in Java by sophia
• 1,400 points
22 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20 in Java by Sirajul
• 40,980 points
209 views
0 votes
5 answers

How to compare Strings in Java?

String fooString1 = new String("foo"); String fooString2 = ...READ MORE

answered Jul 12, 2018 in Java by Daisy
• 8,050 points
147 views
+1 vote
2 answers

How to generate random integers within specific range in Java?

You can achieve that concisely in Java: Random ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
70 views
0 votes
1 answer

How to divide a string in two parts

String s="yourstring"; boolean flag = true; for(int i=0;i<s.length();i++) { ...READ MORE

answered Apr 13, 2018 in Java by Rishabh
• 3,540 points
57 views
0 votes
2 answers

How to round any number to n decimal places in Java?

new BigDecimal(String.valueOf(double)).setScale(yourScale, BigDecimal.ROUND_HALF_UP); will get you a BigDecimal. To ...READ MORE

answered Aug 26 in Java by Sirajul
• 40,980 points
103 views
0 votes
2 answers

How to test that an array contains a certain value?

public static final String[] VALUES = new ...READ MORE

answered Jul 17, 2018 in Java by Sushmita
• 6,880 points
71 views