JavaScript's Number.prototype.toFixed formats a number using fixed-point notation.
Questions tagged [tofixed]
160 questions
2
votes
5 answers
.toFixed function doesn't work with js-object
Why when I want to assign formatted number to variable it shows error?
var jsObject = new Object();
jsObject.number = 0;
for (i = 1; i <= 10; i++) {
jsObject.number += 0.1;
console.log((jsObject.number).toFixed(1)); // works and shows…

dt_
- 95
- 1
- 10
2
votes
2 answers
Use toFixed() to elements of an array
I have an array containing numerical values like this:
myArray = [432.2309012, 4.03852, 6546.46756];
I want to have maximum 2 digits after the dot so I use toFixed(2):
myArray.forEach(a => a.toFixed(2));
The result that is returned is undefined.…

Samurai Jack
- 2,985
- 8
- 35
- 58
2
votes
2 answers
ReactJS: How to fix numerical rows values length with toFixed(2)
I am printing the data fetched from an API into a table, and I am facing some difficulties to fix the rows numerical values to decimals. If the rows data within the API consists of numerical values, i.e. 10.0, 333, 8 or 100, etc. to render it in the…

andimit
- 35
- 1
- 10
2
votes
4 answers
Javascript toFixed() issues
I am having trouble with my toFixed() method. Before I added it onto all the parseFloats, which were already there, it was displaying all the totals but with too many decimal places. Now it displays nothing. When I take the toFixed() off, it…

maria
- 41
- 4
2
votes
1 answer
JQuery toFixed is not a function
I have this JavaScript code:
if($('#numlic').val() <= 10) {
$('#totalprice').text(23.10 * $('#numlic').val()).toFixed(2);
}
but it doesn't work and I get the "toFixed is not a function" error.
Can you help me with this?
Thanks in advance.

user995691
- 89
- 1
- 3
- 13
2
votes
3 answers
Calling the toFixed method on a number literal
When I call the toFixed() method on a decimal number literal like so:
var a = 67.678.toFixed(2);
console.log(a);
The result works and returns 67.68
However if I call the method on an integer - I get an error
var b = 67.toFixed(2);
console.log(b);…

Danield
- 121,619
- 37
- 226
- 255
2
votes
4 answers
How to restrict the price to 2 decimal points
My Html


Zinox
- 519
- 9
- 24
2
votes
2 answers
JQuery ToFixed not working
This is my script: