froadie - 1 year ago 64

Java Question

I have code to calculate the percentage difference between 2 numbers -

`(oldNum - newNum) / oldNum * 100;`

`double`

`int`

`double`

Answer Source

The result of division by zero is, mathematically speaking, **undefined**, which can be expressed with a float/double (as `NaN`

- not a number), it isn't, however, wrong in any fundamental sense.

As an integer must hold a specific numerical value, an error must be thrown on division by zero when dealing with them.