showing results for - "tofixed is not a function javascript"
Emma
02 Jul 2019
1// toFixed only exists on numbers. 
2// Trying to use it on another data type like strings will not work
3// Example
4
5let num = 1.23456;
6num.toFixed(2); // 1.23
7
8num = String(num);
9num.toFixed(2); // Uncaught TypeError: num.toFixed is not a function
10
11// Solutions
12// Convert your string to a number by:
13//  - prepending it with a +
14//		e.g. (+num).toFixed(2);
15//	- using parseInt
16//		e.g. parseInt(num).toFixed(2)
17//	- using Number
18//		e.g. Number(num).toFixed(2)
Erik
05 May 2017
1toFixed isn't a method of non-numeric variable types. In other words, Low and High can't be fixed because when you get the value of something in Javascript, it automatically is set to a string type. Using parseFloat() (or parseInt() with a radix, if it's an integer) will allow you to convert different variable types to numbers which will enable the toFixed() function to work.
2
3var Low  = parseFloat($SliderValFrom.val()),
4    High = parseFloat($SliderValTo.val());