[Solved] Compare 2 Numbers in Java


You can use the doubleValue() method on both numbers and then compare the double values.

If you need a higher precision for integers, you can implement this as sepcial case.

If you have objects that are not an instance of Number (e.g. Object or String containing a “number”), then you should throw all your code away and start from scratch, honestly.

solved Compare 2 Numbers in Java