Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to convert string to integer

Status
Not open for further replies.

theme

Technical User
Sep 5, 2006
2
KE
what's the java command for making a number out of a string

" 42 " -> 42

?
 
Hi,
Try

num = parseInt("42") or
decnum = parseFloat("43.25")

[profile]
 
Just to be safe, use:

parseInt('42', 10);

which converts to decimal. If you use any number starting with a '0', then parseInt will see that as as octal number.

By default,

parseInt('042');

equals 34 in decimal.

Another way to convert a string to numeric value is to just multiply by 1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top