Cashregister Javascript

Following is my code to find the total amount in cash register. I am trying to change the type of total to floating point number using parseFloat but it’s not working. Can someone help me to understand how can i change the type of total to be floating point number.

let total = cid.reduce( (sum, elem) => (sum + elem[1]),0 );
total = parseFloat(total).toFixed(2);

When i run

console.log(typeof total)

it outputs string instead of int

I think this is where you are converting to a string, if I recall how fixed works.


Jeremy is correct.

Return value

A string representing the given number using fixed-point notation.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.