Hi,

How to round double to 2 decimal places java?

Thanks

View Answers

December 18, 2017 at 8:23 AM

Hi,

BigDecimal class can be used in following way:

import java.math.BigDecimal; import java.math.RoundingMode; public class RoundDouble { public static void main(String[] args) { BigDecimal bd = new BigDecimal("203.56849"); bd = bd.setScale(2, RoundingMode.HALF_UP); Double rounded = bd.doubleValue(); System.out.println(rounded); } }

Thanks

Ads

Related Tutorials/Questions & Answers:

round double to 2 decimal places java Hi, How to round double to 2 decimal places java? Thanks Hi, BigDecimal class can be used...) { BigDecimal bd = new BigDecimal("203.56849"); bd = bd.setScale(2

How to round a number to n decimal places in Java How to round a number to n decimal places in Java

Advertisements

Rounding off in Java - Round two decimal places ... to round the figure up to two decimal places in java. Round...: The following program round two decimal places of the given number. It means

php format number to 2 decimal places Hi, How to format a number in PHP to 2 decimal places? Can anyone provide me good code for php format number to 2 decimal places? Thanks

Round the Decimal values How to round the decimal value with out using Math.round() Example:round the 2.7 as a 3.0 round the 2.4 as a 2.0

to round the number up to the 2 decimal places and since 3rd number is greater than... : ROUND( number, [Decimal Places]); Rounds the argument... to the nearest whole number or to the specified decimal places. For getting the whole

Struts 2 double validator The Double validator of Struts 2 Framework checks if the given input is double or not. If the input is not double, it generates the error message. Double

converting string to double in java Please post an example to converting string to double in java. Thanks! Convert String to Double Tutorial

java program to convert decimal in words write a java program to convert a decimal no. in words.Ex: give input as 12 output must be twelve

Intro Java help with Double I have to evaluate a math expression using double in Java. I can input the code fine for the expression, but I don't know how to view the answer that it gives me. help

how to convert string to double in java Hi, I have String variable with double value in it. how to convert string to double in java? Thanks Hi, Use the function: Double.parseDouble(s) of Double class

how to convert string to double in java Hi, I have String variable with double value in it. how to convert string to double in java? Thanks Hi, Use the function: Double.parseDouble(s) of Double class

how to convert string to double in java Hi, I have String variable with double value in it. how to convert string to double in java? Thanks Hi, Use the function: Double.parseDouble(s) of Double class

how to convert string to double in java Hi, I have String variable with double value in it. how to convert string to double in java? Thanks Hi, Use the function: Double.parseDouble(s) of Double class

How to convert binary to decimal in Java program? In this section we are going to convert a binary number to it decimal representation... to Decimal in Java. Computer is based on the binary number format and it just

Java bigdecimal round example In this example, bigdecimal class round method working... and double. Method also throws ArithmeticException if the rounding mode

decimal to hexadecimal using array in java convert decimal to hexadecimal. Hi, Please see the example Convert Decimal to Hexadecimal. Thanks

Conversion of Decimal to Binary in Java In this section we will discuss about conversion of Decimal to Binary in Java. You know that number having base 10 is a decimal number, for example 10 is a decimal number which can

Write a program in Java to convert Decimal number into Binary number Hi, I have decimal number and I want to convert it to Binary. How to Write a program in Java to convert Decimal number into Binary number? Thanks

How to make the single click as double click in java How to make the single click as double click in java... By clicking on a tab, the tab should respond as clicked twice i.e (double click on the tab/button)... Its very urgent

losing precision converting from java BigDecimal to double losing precision converting from java BigDecimal to double

Create Round Button in Java swing In this tutorial, we are going to create a button of round shape. Java2D APIs and Java Swing make it easy to implement custom-shaped buttons. For this you need to extend your class from JButton class

Example to show double exception in java ... exception in java. The given below program tells about the occurrence of double... in an object. Double exception occurs in java when the string or primitive data type

returning doubles with 2 decimals JAVA Hi all. I'm writing a program..., Item (string name, double cost, int qty) { ... } I have a method public double... a Double, not a String!! So when my client queries: item.getCost

java code 1 of 2 Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes Hi Friend, Visit

SQL Decimal SQL Decimal is used to specify the values in decimal datatype. The Decimal datatype can be of two types : Decimal (p) refers to floating point and Decimal fixed

Moire Pattern 2 Java textWhat you are seeing in the screenshot...; g2.setColor(Color.black);g2.fillOval(centerX, centerY - ovalWidth / 2, 300, ovalWidth... - ovalWidth / 2, 300, ovalWidth);g2.rotate(Math.toRadians(15),centerX,centerY