Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Converting "text" number to an actual number

1. ## Converting "text" number to an actual number

In recent postings I was shown how to pass numbers from one web page to another. That works great. The problem I have now is the numbers that were passed are text instead of numbers. Listed below are the numbers that were passed:

num1 = 100
num2 = 200
num3 = 300

If I were to add these numbers together on Page2.htm, the result would look like 100200300 instead of 600. Any ideas as I would convert these to actual numbers?

The posting where I obtain the coding:

http://www.codingforums.com/showthre...241#post162241

• parseInt( string, 10 ); // Integers with a radix of 10. (IOW, decimal integers)

parseFloat( string ); // Floating point numbers, radix of 10. (IOW, decimal floating point numbers)

• Also the Number function is another choice.

• ## It still is not converting the text number to a number

Thanks guys for your help. I'm still having problems, however, converting the textstring numbers to numeric numbers. To test the conversion, I created two numbers, one as a text string and the other as a numeric number. I used the number function, but it didn't convert it. It should have returned the answer:

350.

250100.

Any ideas? I also used the parseInt and got the same results. Listed below are the codes I used.

<script type="text/javascript" language="javascript">
var num1=250
var num2="100"
Number(num2)
newnum=num1+num2
</script>

<script type="text/javascript" language="javascript">
var num1=250
var num2="100"
Number(num2)
parseInt(num2,10);
newnum=num1+num2
</script>

• Ah, the input is not changed when you use those functions - the output from them is changed, however. An example:
Code:
```var
sNumber = '100.1', // => [string '100.1']
iNumber = parseInt( sNumber ), // => [number 100]
nNumber = parseFloat( sNumber ); // =>[number 100.1]

/* The results?
sNumber is still a string '100.1'
iNumber is a number 100
and nNumber is a number 100.1
*/```

• ## Thanks

thanks, that did it. I appreciate the help. I'm glad I found this place.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•