data.map(item => item.Points = item.Points / item.Games);
so i am pulling this data from an api then i am dividing the 2 numbers and i want to round it to the nearest first decimal after because it comes out as 27.77777777 i want it to just be 27.8
data.map(item => item.Points = item.Points / item.Games);
so i am pulling this data from an api then i am dividing the 2 numbers and i want to round it to the nearest first decimal after because it comes out as 27.77777777 i want it to just be 27.8
This is quite easy to do. To preserve one decimal, you can use something like Math.round(num * 10) / 10
. After adding this to you map function, you would get something like this:
data.map(item => item.Points = Math.round(item.Points / item.Games * 10) / 10) / 10));
Here's an example by using dummy numbers:
console.log(Math.round(25 / 4 * 10) / 10);