Originated From
QueryCAT

How can I convert float to String in javascript ?? Need ASAP

Liked this question? Tell your friends about it

2 Answers

Order by
Oldest to Newest
Newest to Oldest
Votes

Javascript will convert types automatically if you just use them in a context where that needs to happen.  For example, you can just add an empty string to your float and the result will be a string:

var x = 3.14952;
var y = x + '';
window.alert( typeof x ); // number
window.alert( typeof y ); // string

You can also do explicit casting, but it's usually not necessary. 

<a href="http://www.boogdesign.com/b2evo/" rel="nofollow">boogdesign blog</a>

robertc is very right. In case you may also be looking for String-to-float: that is not as automatic. You can use the globally defined function parseFloat(f). so parseFloat("0003.1415") would result in 3.1415. ParseFloat (and also parseInt) will skip any leading non-number characters btw, such as US$ e.g.

Related Questions

Other people asked questions on similar topics, check out the answers they received:

Asked Anonymously: Tel-A-Bob Float Co Lima Ohio

Tel-A-Bob Float Co Lima Ohio

Asked: What does hope float mean

what does hope float mean