Sum function

AusQB

New Member
I'm trying to write a simple function that takes a set of numbers from table cells (ie. <td>5</td>) and adds them together.

I can't figure out how to change the number from string form to numeric. Is there a toAlpha function or something similar?
 

jnjc

New Member
Use parseFloat

Code:
<script type="text/javascript">
alert( [B]parseFloat[/B]("1") + [B]parseFloat[/B]("2"));
</script>
 

ashgray2

New Member
To convert a string to a number, use the JavaScript function parseFloat (for conversion to a floating-point number) or parseInt (for conversion to an integer).

parseFloat('string')

The argument of parseFloat must be a string or a string expression. The result of parseFloat is the number whose decimal representation was contained in that string (or the number found in the beginning of the string). If the string argument cannot be parsed as a decimal number, the results will be different in different browsers (either 0 or NaN).
 
Top