Converting Numeric to Float - using JavaScript

# Thread: Converting Numeric to Float - using JavaScript

1. Ed Guest

## Converting Numeric to Float - using JavaScript

Is there any straight forward JavaScript function that can convert a numeric value of 1 to 1.00 (for display purpose on Web page) ?<BR><BR>How can I do this ?<BR><BR>Thanks in advance<BR>-Ed

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: Converting Numeric to Float - using JavaScript

For display purposes, just make it a string:<BR><BR><BR>var i = "1.00";<BR><BR>or <BR><BR>var i = 1 + ".00";

3. Ed Guest

## RE: Converting Numeric to Float - using JavaScript

I&#039;m trying to add field values like .....<BR><BR>1, 2.0 the sum of these values is coming as 3 instead of 3.0.<BR><BR>Thanks<BR>-Ed<BR><BR><BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: Converting Numeric to Float - using JavaScript

parseFloat(yourvar) + parseFloat(yourothervar)

5. Ed Guest

## RE: Converting Numeric to Float - using JavaScript

That&#039;s exactly what I used in summing up...<BR><BR>This is how it&#039;s working...<BR><BR>1 + 2.0 = 3 (should be 3.0)<BR>1.0 + 3.0 = 4 (should be 4.0)<BR>1.25 + 1.25 = 2.5 -&#062; this is Ok !!<BR>

6. Ed Guest

## RE: Converting Numeric to Float - using JavaScript

That&#039;s exactly what I used in summing up...<BR><BR>This is how it&#039;s working...<BR><BR>1 + 2.0 = 3 (should be 3.0)<BR>1.0 + 3.0 = 4 (should be 4.0)<BR>1.25 + 1.25 = 2.5 -&#062; this is Ok !!<BR>

7. Ed Guest

## RE: Converting Numeric to Float - using JavaScript

That&#039;s exactly what I used in summing up...<BR><BR>This is how it&#039;s working...<BR><BR>1 + 2.0 = 3 (should be 3.0)<BR>1.0 + 3.0 = 4 (should be 4.0)<BR>1.25 + 1.25 = 2.5 -&#062; this is Ok !!<BR>

8. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: Converting Numeric to Float - using JavaScript

I don&#039;t know any functions off the top of my head in JavaScript, but you could do something like this:<BR><BR>yourTotal += &#039;&#039;//convert to string<BR><BR>if (yourTotal.indexOf(".") != - 1)<BR> {<BR> yourTotal += ".00";<BR> }<BR><BR><BR>You can also play with it to make sure it has the number of places after the decimal you need.<BR>

#### Posting Permissions

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