I am needing format a data with 8 decimal numbers, eg:
843332 -> 0.00843332
123456789 -> 1.23456789
9876543210 -> 98.76543210
How could I perform this task in JavaScript?
I am needing format a data with 8 decimal numbers, eg:
843332 -> 0.00843332
123456789 -> 1.23456789
9876543210 -> 98.76543210
How could I perform this task in JavaScript?
Just divide by 1e8
:
const translate = num => num / 1e8;
console.log(
[
843332,
123456789,
9876543210
]
.map(translate)
);
function myFunction() {
var value = ["843332", "123456789", "9876543210"];
for(i =0; i < value.length; i++){
document.getElementById("demo").innerHTML += (value[i] /100000000).toFixed(8) + " <br />";
}
}
<p>Click button to generate</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
Please try this.
function myFunction() {
var value = ["843332", "123456789", "9876543210"];
for(i =0; i < value.length; i++){
document.getElementById("demo").innerHTML += (value[i]/100000000).toFixed(8) + " <br />";
}
}