I got this issue.
I want to convert integer 71 (type number) to one decimal, meaning 71.0
but I need it to stay of type number.
Searched and the only solution I found was to use toFixed(1) and then parseFloat on
the result, and that does returns a number but 71, without the decimal.
const float = (num) => {
let fixed = (num).toFixed(1)
let float = parseFloat(fixed)
return float
}
float(71)
How should I do it?
71is the same as71.0, which is the same as71.00, etc. JS truncates unnecessary zeroes for display. If you want a specific format, you need a string.71and71.0are exactly the same.71and71.0are the same in this format.