Java

BigDecimal - why do we need it?

Why do we need it?

This question is the pretty standard one in algorithmic interview questions. So, why do we need it? I think it’s fair to ask. The main reason behind this is knowing how floating point numbers are being stored. Usually, you don’t need it to use this knowledge otherwise to know “solution” but it’s good to know.

The main reason is the precision or rather, the lack of it. In environments where we need to have big numbers very precise like face values and when it’s multiplied by exchange ratios, the potential difference can be very signifcant. Therefore potential financial risk can be signifcant, too.