Numbers: parse, round and check
Form values are strings. Convert them, and check the result before using it.
JavaScript · Numbers: parse, round and checkBeginner
const a = parseInt('42px', 10); // 42
const b = parseFloat('3.14abc'); // 3.14
const c = Number('12abc'); // NaN (strict)
const d = Number.isNaN(c); // true
(1234.5678).toFixed(2); // '1234.57' (a string!)
Math.round(2.5); // 3
Math.floor(-1.5); // -2
0.1 + 0.2 === 0.3; // false: use cents or toFixed for money
const money = Math.round(19.99 * 100); // 1999 centsnumberparseInttoFixedisNaN