# How to deal with Floating-Point Rounding Error

## IEEE 754 Standard

• Sign: This is basically representing the sign of the number (Positive or Negative).
• Exponent: This field represents both positive and negative exponents. A bias is added to the actual exponent in order to get the stored exponent.
• Mantissa: This is part of a number in scientific notation or a floating-point number, consisting of its significant digits.
• In IEEE standard the first bit represents the sign. So, if the sign positive the value will be “0”, and if the sign is negative the value will be “1”. In our case it is positive, that means value will be 0.
• Now we have to consider the Exponent. In this scenario our exponent value is 2^3 (2 to the power 3). So, the Exponent has value of 8 bits to represent itself and exponent should represent both positive and negative (-128 to 127). Before moving to the last part, there is another thing to consider. That is if our exponent is positive, we must add that into the 8-bit representation. So, our exponent is 3 (2^3) and we must add it into the 127, then it becomes 130. Finally convert 130 into binary and it will represent the “Exponent value” in IEEE 754 standard.
• Now all we left to do is add the 9.1’s Binary Scientific Notation as the Mantissa. So, after all these calculations, 9.1’s IEEE 754 representation is look like this.

# Using BigDecimal Class

## More from Nisal Pubudu

Associate Software Engineer at Virtusa

Love podcasts or audiobooks? Learn on the go with our new app.

## Nisal Pubudu

Associate Software Engineer at Virtusa