Javascript Convert Values
Converting a string data type to float in javascript?
How to convert a float, interger value to string?
Explanation
c)
Converting String to FloatTo convert a value from string to float, we have to use the function or method "
parseFloat() to
convert a string value to float.
Example | Result |
|
parseFloat("4.333"); | 4.333 |
|
parseFloat("5aaa"); | 5 |
|
parseFloat("6e2"); | 600 |
|
parseFloat("aaa"); | NaN (means "Not a Number") |
|
d)
Converting Integer/Float to StringInteger (int) or float value can be converted to string by using the function or method toString().
Example | Result |
|
var a = 3.22; a.toString(); | "3.22" |
|
var a = 5; a.toString(); | 5 |
|
Example Code:
<script language="javascript">
var a = 32;
var b = 333;
var c = a.toString()+b;
document.write(" to String function "+c);
</script>
Result:
32333