i have a array coming from api like this
x = [0, 12.1, 23.45, 100.23, 13.99, 90, 0, 16.1]
i want each number with decimal point upto 2, like 0.00 or 12.10
what i did is
x = x.toFixed(x);
but this return string values not number, i need all values as numbers. i am not sure how i can get numbers after converting them to decimals.
someone suggest this code i tried but no success
x = +x.toFixed(2);
i tried parseFloat as well after toFixed but it shows in console its a number but its not, its actually a string.
i am trying this in angular2+ application in primeng table
toFixed) only when you need to display them.1.0000000000 == 1. The only time you should need leading 0s or trailing decimal 0s is when you're displaying them, not operating on them; in which case, as @ibrahimmahrir said, make a string copy for display but operate on the original numbers.