<html>
<script>
function zero ( zeroArray ){
console.log('ZERO ARRAY ' zeroArray)
if(zeroArray !== undefined){
let fixed = parseInt(zeroArray).toFixed(1)
console.log('REPLACE ' fixed.replace(".", ""))
return fixed.replace(".", "")
}
return zeroArray
}
</script>
</html>
- the function appends a 0 when there is an undefined number after the input ie 4 will return 40
- say the input is 4.4, it needs to return 44 and at the moment it returns 40, or say 3.5 should return 35 which returns 30
- thanks for any help provided
CodePudding user response:
function zero(zeroArray) {
if (zeroArray !== undefined) {
let fixed = zeroArray * 10;
return fixed;
}
}
CodePudding user response:
parseInt, rounds it to an integer. Use parseFloat.
Example
parseFloat('10.5').toFixed(1).replace('.',''); // output "105"