I have an array retrieved from an API that looks like this:
x = [0, 12.1, 23.45, 100.23, 13.99, 90, 0, 16.1]
I need each number to have a decimal point up to two places, such as 0.00 or 12.10.
Here is what I tried:
x = x.toFixed(x);
However, this converts the values to strings instead of numbers. I am unsure how to keep them as numbers after converting them to decimals.
Someone suggested this code, but it did not work for me:
x = +x.toFixed(2);
I also attempted using parseFloat after toFixed, but although the console shows it as a number, it is actually still a string.
I am attempting to do this within an Angular 2+ application in a PrimeNG table.