BigDecimal constants

In this chapter you will learn:

  1. What are BigDecimal constants for One, Ten and Zero
  2. Value of 1, 10, and 0 in BigDecimal

Constants for One, Ten and Zero

BigDecimal class is an immutable class and represents a signed decimal number of arbitrary precision with an associated scale. BigDecimal declares three convenience constants: ONE, TEN, and ZERO. Each constant is the BigDecimal equivalent of 1, 10, and 0 with a zero scale.

  • static BigDecimal ONE The value 1, with a scale of 0.
  • static BigDecimal TEN The value 10, with a scale of 0.
  • static BigDecimal ZERO The value 0, with a scale of 0.

BigDecimal(0.1) results in 0.100000000000000005 being stored in the instance. BigDecimal("0.1") stores 0.1 exactly.

Value of 1, 10, and 0 in BigDecimal

  • static BigDecimal ONE The value 1, with a scale of 0.
  • static BigDecimal TEN The value 10, with a scale of 0.
  • static BigDecimal ZERO The value 0, with a scale of 0.
import java.math.BigDecimal;
/* jav  a 2 s  . c om*/
public class Main {
 
    public static void main(String[] args) {
        System.out.println(BigDecimal.ONE);
        System.out.println(BigDecimal.TEN);
        System.out.println(BigDecimal.ZERO);
        
    }
}

The output:

Next chapter...

What you will learn in the next chapter:

  1. What are the rounding mode for BigDecimal
  2. Use different rounding mode to do calculation
Home » Java Tutorial » Data Types

Java Primitive Data Types
Java byte type
Java byte type conversion
Java short type
Java short type conversion
Java int type
Java int type conversion
Java long type
Java long type conversion
Java float type
Java float type conversion
Java double type
Java double type creation and comparison
Java double type conversion
Java Automatic Type Conversion and Casting
Data type casting
Java type promotion
Java char type
Java char conversion
Java char value and its attributes
Java boolean type
Java boolean type conversion
Autoboxing and auto-unboxing
Java Array
Create an Array
Array Index and length
Multidimensional Arrays
Array examples
Array copy
Array compare
Array Binary search
Array sort
Array to List
Array fill value
Array to String
BigInteger class
BigInteger creation
BigInteger add, subtract, multiply and divide
BigInteger power and modPow
BigInteger conversion
BigInteger to String
BigInteger bit and,or,xor,test,flip,negate
BigInteger bit shift left and right
BigInteger prime value
BigDecimal
BigDecimal constants
BigDecimal Rounding mode
BigDecimal creation
BigDecimal calculation
BigDecimal convert
BigDecimal Comparison
BigDecimal to String
BigDecimal decimal point
BigDecimal precision
BigDecimal format
Currency class