JavaScript's Number.prototype.toFixed formats a number using fixed-point notation.
Questions tagged [tofixed]
160 questions
0
votes
1 answer
Looking for help adding a .toFixed to jquery.
Hey everyone looking for a bit of help adding a .toFixed to a variable in jquery.
< script type = "text/javascript" > $(document).ready(function() {
var a = $("#address").text();
…

Infernoman
- 33
- 8
0
votes
4 answers
Round every textbox to 2 decimal places
This is probably really simple, but for the life of me I can't work out how to do it. So here goes: I have a large form with lots of text boxes, which are all currency based and so need to be rounded off to 2 decimal places. The values of these…

Tom Oakley
- 6,065
- 11
- 44
- 73
0
votes
1 answer
Math.round and toFloat and custom function wont round to 2 decimals
I have a mortgage calculator and I want the two outputted values to be rounded to 2 decimal places. Here is the website http://hawkstonefs.duneroot.com, as you can see it isn't rounding at all.
Below is my code, I have tried toFloat(2), Math.round…

Rik89
- 157
- 4
- 22
0
votes
1 answer
PhoneGap geolocation object doesn't like rounding?
I've created a demo PhoneGap application, that checks acceleration, compass and geolocation and presents these info to user. Application was compiled using PhoneGap Build.
I used simple toFixed(n) and some strings to round value and add some unit…

trejder
- 17,148
- 27
- 124
- 216
0
votes
3 answers
toFixed(); is only returning .00
The below code is returning decimal places, but it's not returning values other than .00, when I have my values set to .67, 1.33, 2.67, etc.
$(function($) {
$('#CourseMenu select').change(function() {
var sum = 0;
$('#CourseMenu…

Millhorn
- 2,953
- 7
- 39
- 77
0
votes
2 answers
My toFixed(); isn't working
I have the following JS here...
$(function($) {
$('#CourseMenu select').change(function() {
var sum = 0;
$('#CourseMenu select').each(function(idx, elm) {
sum += parseInt(elm.value, 10);
});
…

Millhorn
- 2,953
- 7
- 39
- 77
0
votes
2 answers
jquery round to 2 decimal places not working as expected
I am using the following Jquery script to calculate totals in realtime on my invoices, the problem is I cant seem to get subtotal to round to 2 decimal places.
If I add the line :
subtotal= (subtotal).toFixed(2);
after
subtotal +=…

Iain Simpson
- 8,011
- 13
- 47
- 66
0
votes
1 answer
Javascript Method Chaining: Correct method chain toFixed() and parseFloat() to return a number, not a string?
Most important thing here is that I can NOT set a variable, needs to be on the fly:
Dealing with latitude. Let's call it lat. Let's say in this case lat is 123.4567
lat.toFixed(2).parseFloat();
TypeError: Object 123.35 has no method…

Nubtacular
- 1,367
- 2
- 18
- 38
0
votes
1 answer
Is it possible to cast NaN from "NaN" (string) ( using toFixed() )
So I got why to fixed returns a String, with this in mind is it possible to cast the "NaN" string into NaN to keep the following expression workable?
var numberWithPrecission = (1*"A").ToFixed(2) || 0;

Jonathan DS
- 2,050
- 5
- 25
- 48
0
votes
3 answers
Javascript calculation for a data loop with no decimals
I am trying to calculate prices for a loop of elements :
function calculateBill(id,price)
{
var t = document.getElementById('total').value;
var qty = document.getElementById('qty_'+id).value;
var total = qty * price;
var tcost =…

Nitish
- 2,695
- 9
- 53
- 88
-1
votes
2 answers
why this Floating point addition can be solved only by multiply all the figures by ten?
Because of Floating point arithmetic in Javascript, i understand 0.2 + 0.1 = 0.30000000000000004 will be in Javascript, but i don't understand why only multiply the figures by 10 i.e. let x = (0.2 * 10 + 0.1 * 10) / 10;, then the problem can be…

eric2023
- 9
- 2
-1
votes
1 answer
How to round a number in JavaScript without using toFixed()
I am trying to round numbers to a certain decimal place, the expected API would be something like this:
const rounded = Math.round(1.6180339, 5);
or
const rounded = new Number(1.6180339).round(5);
but those APIs don't seem to exist. I have this…

Alexander Mills
- 90,741
- 139
- 482
- 817
-1
votes
1 answer
Rounding a half of number in js
Different types of rounding and different result
Why is it, I was checking the mathematics rules, where was saying that after 0.5 we are rounding to 1 but in the second operation rounded to 0 and gives me the wrong answer
-1
votes
2 answers
Cannot read property 'toFixed' of undefined
im a beginner at javascript and would appreciate some help
The question:
pete's pizza place is famous for great pizza at reasonable prices. Make a program that will help pete compute the price on the orders. make sure you add on 13% tax and that…

caitlinicecream
- 11
- 1
-1
votes
2 answers
toFixed() method working isn't inside number() method in javascript?
What I want: after calculation result should be in 2 decimal format.
here's my code
let totalNetWeightLocal = 0;
totalNetWeightLocal = totalNetWeightLocal + Number((parseFloat(item.netWeight) * parseInt(item.quantity)).toFixed(2));
Problem:…

siddharth verma
- 40
- 6