Okay, I’m fairly new to java but I’m learning quickly(hopefully). So anyway here is my problem:
I have a string(For example we will use 2.9), I need to change this to either int or long or something similar that I can use to compare to another number.
As far as I know int doesn’t support decimals, I’m not sure if long does either? If not I need to know what does support decimals.
This is the error: java.lang.NumberFormatException: For input string: "2.9" with both Interger.parseInt and Long.parseLong
So any help would be appreciated!
Both
intandlongare integer values (beinglongthe representation of a long integer that is an integer with a higher capacity). The parsing fails because those types do not support a decimal part.If you were to use them and enforce a casting you’re relinquishing the decimal part of the number.
Use
doubleorfloatinstead.