In this section, you will learn about how to round the figure up to two decimal places in java.
Round: This is the process of rounding with dollar amounts and provides the result in more than two decimal places after division. There are following methods to used in rounding the data:
Methods Data Rounded Data
Round Half
Up
45.558
45.56
Round Half Down
45.555
45.55
Round
Up
45.558
45.56
Round Down
45.558
45.55
Description of program:
The following program round two decimal places of the given number. It means numbers are rounded into the above methods and shows the number in two figures after decimal point. Here, apply the Round() method for rounding the given number and print the following output.
Here is the code of program:
public class RoundTwoDecimalPlaces{
|
Output of program:
| C:\vinod\Math_package>javac RoundTwoDecimalPlaces.java C:\vinod\Math_package>java RoundTwoDecimalPlaces Rounded data: 2.95 |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Rounding off in Java - Round two decimal places View All Comments
Post your Comment