Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

New and need help. Exception in thread "main" java.lang.NumberFormatException: For input string:  RSS feed

 
nate armstrong
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi everyone, I'm having a hard time fixing my code, It runs but as soon as i enter a number and hit enter it crashes giving me the error
Exception in thread "main" java.lang.NumberFormatException: For input string: "$137.50"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
at java.lang.Float.parseFloat(Float.java:451)
at Discountt.main(Discountt.java:27)
When i debug the program it tells me something is wrong with


This is also my 1st time using float

 
Les Morgan
Rancher
Posts: 752
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, to start off with $137.50 is not an int, so yes, you're program is going to complain when you enter something other than an int that you are asking for.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception is coming because the parseFloat method does not know what to do with the $ sign.

Looking at it though, you are parsing a currency string you have just formatted.

Suggestion: don't format the number to do calculations with. Just run the calculation, then you don't NEED to use the parseFloat method.



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!