BigDecimal constants
In this chapter you will learn:
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;
//from j av a 2 s. com
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:
Home » Java Tutorial » BigDecimal BigInteger