export function calculateDiff(first, second){
const firstNum = Number(first);
const secondNum = Number(second);
return isNaN(firstNum) || isNaN(secondNum) || firstNum === 0 ? '' : firstNum - secondNum
}
// In spec test file
it('calculateDiff', () =>{
expect(calculateDiff('',1.2)).toBe('') //PASSES as expected
expect(calculateDiff(100.2399, 99.2455)).toBe(0.9944); //FAILS -result is 0.9943999999999988
expect(calculateDiff(100.2399, 99.2455)).toBe(0.9943999999999988); //PASSES
});
How can I prevent it from making this conversion? I like Number rather than parsefloat function because of the way it does Nan and handles others values.