I have an array of array
array=[[27536, 29675, 71974, 17187],
[42972, 27113, 91087, 25581],
[53533, 36305, 110376, 38949],
[45201, 26403.1, 93274, 30133],
[45869, 31981.63, 85988, 21120],
[58265, 36418.2, 109869, 25167],
[0, 32140.37, 0, 0],
[0, 36124.11, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 1],
[273376, 256160.41, 562568, 158137]];
and i am adding the values like
var result1=array.map(item => item.reduce((a, b)=> a + b, 0));
It is working fine but the output i am getting after this has many digits(last one) after .
[146372, 186753, 239163, 195011.1, 184958.63, 229719.2, 32140.37, 36124.11, 0, 0, 0, 1, 1250241.4100000001]
I want the number to have 2 digits after .
. I tried something like this but the values i am getting is in string.
var result=array.map(item => item.reduce((a, b)=> a + b, 0).toFixed(2));
Any suggestion how can i achieve the same as Numbers?
array=[[27536, 29675, 71974, 17187],
[42972, 27113, 91087, 25581],
[53533, 36305, 110376, 38949],
[45201, 26403.1, 93274, 30133],
[45869, 31981.63, 85988, 21120],
[58265, 36418.2, 109869, 25167],
[0, 32140.37, 0, 0],
[0, 36124.11, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 1],
[273376, 256160.41, 562568, 158137]];
console.log(array);
//Converting in string
var result=array.map(item => item.reduce((a, b)=> a + b, 0).toFixed(2));
console.log(result)
//Too many digits after "."
var result1=array.map(item => item.reduce((a, b)=> a + b, 0));
console.log(result1)