• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string to number

 
ngoc thai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear JR members,
What is the best way to convert a string of digits to either an integer, float or double? Please advice.
Here are the two sample strings: "28769", "78.14159"
Thanks
NT
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the float, use the static method Float.parseFloat(String s)
for the int, use the static method Integer.parseInt(String s)
etc.
etc.
Each primitive wrapper class has a method like this.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ngoc,
To format the float or double values you can use:
java.text.DecimalFormat.
Regards,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic