aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes converting string integer value to real integer value for looping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "converting string integer value to real integer value for looping" Watch "converting string integer value to real integer value for looping" New topic
Author

converting string integer value to real integer value for looping

steve kelly
Greenhorn

Joined: Feb 15, 2012
Posts: 28
OK this should be simple but I am scratching my head on it. I have a string value of an number within an html page(works fine). I then want to convert it to an integer so I can iterate through a fixed number of fields(totalSize var).
Code snippit below. I get this NaN value (putting totalSize inside of an alert())when doing parseInt. I want to be able to iterate through "totalSize". How do I do that once I have the correct string representation of my integer? Is there something I need to call on the Nan value to do it or?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

parseInt() should work fine, even if there's trailing spaces in the string. What exactly does the string contain?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
steve kelly
Greenhorn

Joined: Feb 15, 2012
Posts: 28
Bear Bibeault wrote:parseInt() should work fine, even if there's trailing spaces in the string. What exactly does the string contain?

Never mind. Gah, I was passing in wrong value. I need coffee<grin>
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
When using parseInt, you really should use a radix.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

steve kelly wrote:I need coffee<grin>

Ah yes, uncaffeinated coding -- it's a killer!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: converting string integer value to real integer value for looping