GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||
GeezerVison is showing www.tutorialspoint.com — Java.math.RoundingMode Enumeration
Selected Reading
Java.math.RoundingMode EnumerationIntroductionThe java.math.RoundingMode enumeration specifies a rounding behavior for numerical operations capable of discarding precision. Each rounding mode indicates how the least significant returned digit of a rounded result is to be calculated. If fewer digits are returned than the digits needed to represent the exact numerical result, the discarded digits will be referred to as the discarded fraction regardless the digits' contribution to the value of the number. In other words, considered as a numerical value, the discarded fraction could have an absolute value greater than one. This enum is intended to replace the integer-based enumeration of rounding mode constants in BigDecimal (BigDecimal.ROUND_UP, BigDecimal.ROUND_DOWN, etc. ). Enum declarationFollowing is the declaration for java.math.RoundingMode enum − public enum RoundingMode extends Enum<RoundingMode> ConstantsFollowing are the constants for java.math.RoundingMode enum −
Enum methods
ExampleThe following example shows the usage of math.RoundingMode methods. package com.tutorialspoint;
import java.math.*;
public class RoundingModeDemo {
public static void main(String[] args) {
// create 2 RoundingMode objects
RoundingMode rm1, rm2;
// create and assign values to rm and name
int rm = 5;
String name = "UP";
// static methods are called using enum name
// assign the the enum constant of rm to rm1
rm1 = RoundingMode.valueOf(rm);
// assign the the enum constant of name to rm2
rm2 = RoundingMode.valueOf(name);
String str1 = "Enum constant for integer " + rm + " is " +rm1;
String str2 = "Enum constant for string " + name + " is " +rm2;
// print rm1, rm2 values
System.out.println( str1 );
System.out.println( str2 );
String str3 = "Enum constants of RoundingMode in order are :";
System.out.println( str3 );
// print the array of enum constatnts using for loop
for (RoundingMode c : RoundingMode.values())
System.out.println(c);
}
}
Let us compile and run the above program, this will produce the following result − Enum constant for integer 5 is HALF_DOWN Enum constant for string UP is UP Enum constants of RoundingMode in order are : UP DOWN CEILING FLOOR HALF_UP HALF_DOWN HALF_EVEN UNNECESSARY Advertisements
| ||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |