// toFixed only exists on numbers. // Trying to use it on another data type like strings will not work // Example let num = 1.23456; num.toFixed(2); // 1.23 num = String(num); num.toFixed(2); // Uncaught TypeError: num.toFixed is not a function // Solutions // Convert your string to a number by: // - prepending it with a + // e.g. (+num).toFixed(2); // - using parseInt // e.g. parseInt(num).toFixed(2) // - using Number // e.g. Number(num).toFixed(2)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter