I have the following script:
var x = "202101000000";
var y = 0;
//bilhao
if(x.length >= 10 && x.length <= 12){
if (x.length == 10){
y = x.substr(0,1);
}else if(x.length == 11){
y = x.substr(0,2);
}else if(x.length == 12){
y = x.substr(0,3);
}
if(y.length == 1){
document.getElementById('totalneuro').innerHTML = y + ' bilhão';
}else{
document.getElementById('totalneuro').innerHTML = y + ' bilhões';
}
}
<div id="totalneuro"></div>
It happens that it gives me as a result of the value, the number "202 billion", when I would like the value to come with 2 decimal places, in this case, "202.10 billion." How could I solve this? If anyone knows how to make this code smaller and can help me, thank you!