You are not logged in.

#1 2012-07-26 03:38:49

Muhammad
User RankUser RankUser RankUser RankUser RankUser Rank
بِسمِ اللَّهِ الرَّحمٰنِ الرَّحيمِ
From: Sahiwal Division
Registered: 2012-03-22
Posts: 16,336
Website

How to convert a string into float using JavaScript?

Convert String Into Float Using JavaScript:


Suppose we have a value that contains coma like 200,52600 then how to convert this string value to the float in javascript.

Replace the comma with a dot then it will be able to convert into a float value by using javascript.

var value = parseFloat("200,52600");
This will only return 200:

var value = parseFloat("200,52600");
This will return 200.52600:

So in the end, we can simply use below code.
var fValue = parseFloat(document.getElementById("textfieldid").value.replace(",","."))

Do not forget that parseInt() should only be used to parse integers (no floating points). In this case it will only return 200. Additionally, calling parseInt() on a float will not round the number: it will take its floor (closest lower integer).


Online Web Tutorials And Interview Questions With Answers Forum:
http://www.globalguideline.com/forum/

2012-07-26 03:38:49

Advertisement
Ads By Google

Re: How to convert a string into float using JavaScript?



The following user say "Thank You" for this post:Guest

#2 2012-10-16 13:04:01

maire.oldfield
User RankUser RankUser RankUser RankUser RankUser Rank
Member
Registered: 2012-10-16
Posts: 5

Re: How to convert a string into float using JavaScript?

This is vary nice information in java Script ....   these information is vary useful for me and other java script user ................ thanks for sharing this nice information.......

The following user say "Thank You" for this post:Guest

Board footer