Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion in parseDouble and parseInt

 
Niki Nono
Ranch Hand
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am a bit stumped on why
Double.parseDouble(" 244") gives me 244 as output and
Integer.parseInt(" 244") gives NumberFormatException at runtime.


following is sample code




can anyone please explain???
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
parseDouble() trims the white space, parseInt() does not.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The documentation for the standard Java API should be your first resource when encountering such questions. Find the docs for the version of Java you are using and bookmark them. Learn to navigate it so you can find these odd idiosyncracies between similar methods and other invaluable information about the classes and methods that are available.

Layne
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic