Questions tagged [tofixed]

JavaScript's Number.prototype.toFixed formats a number using fixed-point notation.

160 questions
3
votes
1 answer

toFixed not working on input keyup change

I have this input form where I have price, buyer price, and discount. what I want to do is when buyer price has the value, discount automatically count and change value. I have already done that, but what i want to do is the discount value only up…
Dava Eranda
  • 69
  • 1
  • 6
3
votes
3 answers

javascript/jquery: how to limit input value to 2 decimals after the point

I am struggling with an input which should give me the substraction from input B - input A in 2 decimals after the point. It works only sometimes: $('.b').on('keyup', function() { var substr = $('.b').val() - $('.a').val(); …
Jack Maessen
  • 1,780
  • 4
  • 19
  • 51
3
votes
3 answers

javaScript Rounding decimals using toFixed

I am facing an issue with rounding decimals in JavaScript using toFixed. const num1 = (100.555).toFixed(2) // "100.56" const num2 = (10.555).toFixed(2) // "10.55" Can any one explain why this behavior happens? Why first example round the decimals…
Saif Adnan
  • 307
  • 3
  • 12
3
votes
1 answer

Searching toFixed with "in" operator - How does the "in" operator work on primitives?

I started reading YDKJS for fun - and found that he's written: we can do stuff like: var num = (1.2).toFixed(1) so - this means that toFixed is being invoked as a member method from an integer value. So why doesn't this work?? "toFixed" in…
Probosckie
  • 1,585
  • 4
  • 25
  • 40
3
votes
2 answers

Parse Float and toFixed()

I have my code and it is working, but I'm trying to add the parseFloat option and 'toFixed()' to 2 decimal places. I'm confused on where these 2 lines of code should be placed. I created a unit conversion website that would convert the number of…
Mark
  • 31
  • 1
  • 5
3
votes
1 answer

Lack of precision of the toFixed method in javascript

I have do some test about Number.prototype.toFixed method in chrome(v60.0.3112.101) console and found sth puzzled me. Why 1.15.toFixed(1) return "1.1" but not the "1.2"? Why 1.05.toFixed(1) return "1.1" but not the "1.0"? and so on... I do…
Ye Shiqing
  • 1,519
  • 2
  • 15
  • 24
3
votes
1 answer

parseInt value from input and use as a check for the sum of last value with Javascript

Trying to track the numbers in an input value and use these as a checkdigit for the last number. Basically, grab the first nine digits of the input, run some simple math and then add those numbers together. Take that total, divide by two then use…
isaac weathers
  • 1,436
  • 4
  • 27
  • 52
2
votes
2 answers

ReactJS Function at odds with toFixed

When the HandlePayNow function is called, it executes all of its intended functionality but then crashes the system. It sends the order data to the API, the API logs it and returns a success message, the function gets this success message, it…
2
votes
1 answer

Javascript unable to apply toFixed() to a function

I have made a compounding calculator function and I am unable to apply toFixed() to it. What I basically want to do is apply toFixed(2) in order to get just two digits after the decimal. Here comes the code thank you very much in advance. const…
2
votes
3 answers

Overwrite toFixed() with appropriate replacement to fix floating point error javascript

This is my attempt to fix the JavaScript toFixed() function... Any input, ideas, corrections for possible errors are much appreciated! Fix floating point inacurracy (example (35.355).toFixed(2) = 35.36, not 35.35) No big additional…
DavidDunham
  • 1,245
  • 1
  • 22
  • 44
2
votes
1 answer

How to display second zero when only single digit is returned after decimal, in JavaScript?

I have two functions here... function getCostOne() { var cost = 1.5; return 1 * cost.toFixed(2); } and... function getCostTwo() { var cost = 1.5; return 1 + cost.toFixed(2); } What is the difference between multiplying cost.toFixed(2)…
Millhorn
  • 2,953
  • 7
  • 39
  • 77
2
votes
3 answers

parseFloat & toFixed only returning 1 decimal point

Working on the below, when logging the array 'tips' it seems that the numbers pushed into it have only one decimal point. Before adding in parseFloat it would return 2 decimal points, however it was returned as a string. Once parseFloat was added it…
Cal
  • 95
  • 1
  • 7
2
votes
1 answer

How to use toFixed() method

I would like to ask about the toFixed() method and its usage. I have a const called calories, which is a numeric data and I would like to round it to number with 2 decimal places. const recipe = this.state.activeRecipe; const calories =…
2
votes
4 answers

Uncaught TypeError: Cannot read property 'toFixed' of undefined

I know that others have had this error thrown but I think I have some sort of syntax problem that's causing this to happen for me. If you can find it I would be grateful. I'm new to JavaScript and have been staring at this simple program for an…
Sarah Cohen
  • 706
  • 1
  • 7
  • 11
2
votes
3 answers

What is the rule behind toFixed() function

I'm testing toFixed() method of javascript. The result is seen as below. (49.175).toFixed(2) => "49.17" (49.775).toFixed(2) => "49.77" (49.185).toFixed(2) => "49.19" (49.785).toFixed(2) => "49.78" (49.1175).toFixed(3) =>…
serefbilge
  • 1,654
  • 4
  • 29
  • 55
1
2
3
10 11