Questions tagged [parsefloat]

parseFloat is a global JavaScript method which parses an argument, and returns a number.

JavaScript's parseFloat attempts to parse the first argument, and returns a number. If the argument cannot be parsed, parseFloat returns NaN.

A comparison of number conversion methods can be found at this answer.

222 questions
1
vote
1 answer

How to make a result from a calculator, e.g .: Result: (result of adding)

If you enter 2 numbers in 2 fields, addition and multiplication will be displayed at the same time. After execution, he has to write e.g. Adding: (result of addition) Multiplication (result of multiplication) with one button . How to make from this…
popo
  • 39
  • 3
1
vote
1 answer

I am trying to write a JavaScript program that calculates gross pay, overtime, netpay and deducts taxes from the netpay based on dependants claimed

I have the first half of the program running fine which gets the users hours worked and payrate and then prints the gross pay with overtime pay if there is any. But I need to print the net pay to the screen. The second half of the program asks how…
1
vote
1 answer

Parsefloat and currency issues

I am using this variable on autoFill extension to get a string on the page and put it on a field on the same page. minPrice = javascript:(document.getElementsByClassName('market_commodity_orders_header_promote')[1].innerHTML.replace("R$ ","")) My…
Mirage
  • 13
  • 3
1
vote
4 answers

How fast is parseFloat Vs. float ints in JavaScript?

I'm getting a huge dataset from a client's internal API. It'll contain a bunch of numerical data of prices such as: $31.23. He gives them to me as {"spend":"21.23"} which is fine, but I was concerned that after 1000+ items and running parseFloat()…
Oscar Godson
  • 31,662
  • 41
  • 121
  • 201
1
vote
2 answers

I want to take an input and use it as a parameter of a function in javascript

function myfunc(num,fix) { alert(num.toFixed(fix)); } myfunc(2.222, 2); In the above code, 2.222 and 2 are hard-coded. I want to take these values from a user. I have tried the following solution but it seems that it can be run without parameters…
Syed Zeyad
  • 21
  • 5
1
vote
1 answer

Number formatting with toFixed() and toLocaleString()

I need to format numbers in a given way for my website. Here is my problem : I have 3 different cases : 1) First case : When my number is negative, I have to put parenthesis around it, and display its absolute value. The thing is, I have to keep…
cocool97
  • 1,201
  • 1
  • 10
  • 22
1
vote
1 answer

JS method parseFloat does not return correct value

parseFloat("-999999999999999.9991") returns -1000000000000000 and when debuging (-1000000000000000 == -999999999999999.999) condition is true.
Colin
  • 11
  • 1
1
vote
3 answers

parseFloat returning NaN when converting var from array JavaScript

Im trying to convert a value to float, that i get from an array, but it always comes out as NaN, even though it starts with a number. What am i doing wrong? var lat = ; for(var i = 0; i
Ziggster
  • 21
  • 2
1
vote
2 answers

JavaScript numbers not adding correctly every time parseFloat toFixed

I am calculating subtotal, tax, shipping and insurance based on the following: public getSubTotal() { this.subTotal = document.getElementById("total").value - (document.getElementById("total").value * 0.07 + …
kronus
  • 902
  • 2
  • 16
  • 34
1
vote
2 answers

Remove trailing zeroes to 2 decimal positions

I would like your help with the following: I have prices which could be more then 2 decimal points, i.e. 0.009 or 0.0014 However, I also have prices which have regular prices like 2.9 or 14.45. I store all prices up until 4 decimal points i.e. 2.9…
King Leonidas
  • 23
  • 1
  • 8
1
vote
1 answer

parseFloat() inside forEach() not working

can anyone help me understand why this code doesn't work? Don't know where I'm going wrong. let ratings = ["8.8", "8.6", "9.0", "8.3"]; ratings.forEach(rating => { return parseFloat(rating)} ); I just get undefined.
Lauren
  • 109
  • 2
  • 11
1
vote
2 answers

Sum of toFixed not working correctly

I have the following code that calculates and shows the sum of two values. var oldprice_formated = parseFloat(oldprice).toFixed(2); var extraPrice = parseFloat(3).toFixed(2); if(initials != '') { var new_price = oldprice_formated +…
1
vote
2 answers

Calculation with parseFloat looses decimal places

I need to calculate a few numbers. It works ok so far, BUT it looses the original decimal places (here: 50 cent). Any idea why this is happening? $("select").on("change", function () { var sum1 = parseFloat($(this).val()) *…
JonSnow
  • 573
  • 14
  • 48
1
vote
4 answers

How can i return a float from an a string of numbers?

I have a string of numbers when i do svg.getAttribute("d") in the…
1
vote
1 answer

Getting Value Of HiddenField and passing into var in JS

I'm trying to take the values from 2 asp:HiddenFields and storing them into the var latitudeDB, var longitudeDB in JavaScript. These 2 values set into the HiddenFields are from my database. I have already checked with Debug.WriteLine to check the 2…
domster
  • 556
  • 2
  • 8
  • 26