Manejo de monedas

by Miguel Roman

JavaScript

const numberA = 100.03
const numberB = 200.01;
const total = numberA + numberB;

console.log("this must be 300.04 but is: ", total);

// first and simple approach:
const totalB = new Number((numberA + numberB).toFixed(2));
console.log('Using a combination of toFixed(2) and Number class work like a charm', totalB);

// another alternative we discuss in the live sessión:
const totalC = (numberA * 100 + numberB * 100) / 100;
console.log('Using pennies: Multiplying by 100 and then dividing by 100', totalC);