How do you subtract BigDecimal?
Category:
technology and computing
programming languages
subtract(BigDecimal subtrahend, MathContext mc) returns a BigDecimal whose value is (this - subtrahend), with rounding according to the context settings. If subtrahend is zero then this, rounded if necessary, is used as the result. If this is zero then the result is subtrahend. negate(mc).
Also know, how do I use BigDecimal?
Using a BigDecimal implies that you should:
- Create new BigDecimal variables, using the constructor.
- In order to add a BigDecimal to another BigDecimal, use add(BigDecimal augend) API method, that returns a BigDecimal whose value is (this + augend), and whose scale is max(this.
Similarly, it is asked, can BigDecimal be negative?
A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale.
They are very different. Besides the difference in precision, the most important difference is that BigDecimal is a specifically decimal type. That means it's designed to represent fractions with finite-length decimal (base-10) representations. On the other hand, double is a base-2 floating-point number.