JSFiddle - React, Tailwind, and code Playground
by Alexander
JavaScript
console.clear();
const parseNull = n => n === null || n === undefined ? 0 : n;
const parseNaN = n => isNaN(n) ? 0 : n;
const toFixed = n => n % 1 === 0 ? n : n.toFixed(2);
const toString = n => n.toString();
let f = num =>
(
[num]
.map(parseNull)
.map(parseFloat)
.map(parseNaN)
.map(toFixed)
.map(toString)
[0]
);
['15%', 128, 'a5', {foo:1}]
.map(f)
.map(console.log)