This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript 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: 767
19
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: 1836
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.



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!