I want Conversion from Number to Float in JavaScript
function circumference(r) {
return parseFloat(r);
}
console.log(circumference(4));
expected output: 4.00
I want Conversion from Number to Float in JavaScript
function circumference(r) {
return parseFloat(r);
}
console.log(circumference(4));
expected output: 4.00
You can use toFixed()
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
function financial(x) {
return Number.parseFloat(x).toFixed(2);
}
console.log(financial(4));
Use Number.prototyp.toFixed()
function. You can pass the number of decimal places as the argument.
function circumference(r) {
return r.toFixed(2);
}
console.log(circumference(4));
use parseFloat().toFixed() like this :
var number = parseFloat(4).toFixed(2);
console.log(number);
There's a detailed explanation given on w3Schools with this link having the example to it.
var num = 5.56789;
var n = num.toFixed(2);
console.log(n);
Hope this helps.