tofixed is not a function in javascript - Google Search

PHOTO EMBED

Thu Jan 13 2022 21:33:36 GMT+0000 (UTC)

Saved by @Samo_Krose #javascript

// 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)
content_copyCOPY

https://www.google.com/search?q