Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parseXxx()

 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,



Why does this work


while this does not


Thanks.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this code, dd (without quotes) is a variable that holds a value of 3.2. But "dd" (with quotes) is a String literal that has nothing to do with the variable or its value. So "dd" has no meaning as a float.

"3.2" (with quotes) is also a String literal, but it is in a format that can be parsed to a float.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replyin Marc. I get it now.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to assign the value of variable dd to your float, just assign it (with a cast to make sure it fits):
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic