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
0 answers

d3.js: How to import csv data with float and string types

Very new to d3 and javascript, but have done a good four or so hours trying to resolve this issue and haven't found a solution yet. My .csv dataset I'd like to use has both string and float numbers (see sample set here:…
user1301593
  • 631
  • 1
  • 6
  • 16
1
vote
1 answer

Javascript, Finding largest number sequence in a String

In Javascript, I'm trying to make a function which will find the longest number in a string and convert it to a floating point value. However, when I input something like ff333sds22442, it will output "333" as the longest number when it should…
1
vote
1 answer

jquery parseFloat assigning val to field

I have a select box that gives a description of a product along with a price. Depending on what the user selects, I'd like to automatically grab that dollar amount from the option selected and assign it to a price input field. My HTML: …
user306472
  • 363
  • 2
  • 8
  • 12
1
vote
3 answers

Why does my textarea (HTML) value show 12,000,000.11 but after parseFloat the value is only 12?

I am attempting to develop a conversion website that takes a numeric value: 1,200.12 or 1.200,12 or 1200.12 or 1200,12 and have them all interpreted as 1200.12 by parseFloat. I would also like decimals to be able to be interpreted. 0.123 …
1
vote
2 answers

parseInt() and parseFloat(): Can this second assertion ever fail?

I've been using parseInt() and parseFloat() in various contexts for a while now, and I'd like to think I know all the ins and outs of the two. But recently I had a curious thought which I so far haven't been able to definitively work out a proof…
smitelli
  • 6,835
  • 3
  • 31
  • 53
1
vote
2 answers

How to replace expression in a string with its value?

Sorry if the question is worded badly, but what I'm trying to ask is, How would you replace a substring of a string in JS with the product of two of the captured groups? To see what I mean, look at the following line. How would I perform a task like…
Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
1
vote
2 answers

jQuery - parseFloat returns different values when used

In this code : $("div#info_holder").css("marginLeft", "100%"); alert(parseFloat($("#info_holder").css("marginLeft"))); alert(parseFloat(document.getElementById("info_holder").style.marginLeft)); the first alert returns 1037.78, the second alert…
dodov
  • 5,206
  • 3
  • 34
  • 65
1
vote
1 answer

parseFloat of string longer than 16 characters

Does parseFloat of a string have a limit to how many characters the string can be? I don't see anything about a limit here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat But running the following in…
edward.louis
  • 357
  • 2
  • 5
  • 14
1
vote
2 answers

Why isn't this javascript with else if working?

I'm sorry I can't be any more specific - I have no idea where the problem is. I'm a total beginner, and I've added everything I know to add to the coding, but nothing happens when I push the button. I don't know at this point if it's an error in the…
Uni
  • 1,371
  • 4
  • 11
  • 9
1
vote
1 answer

Javascript parseFloat 10 instead of e

Im using parseFloat on very high numbers or very low numbers. The return value is like 123*10e15 , I need to be like 123*10^15 . 15 needs to be in upper writing as a pow. Thanks.
Vera Gavriel
  • 381
  • 2
  • 5
  • 14
1
vote
2 answers

Odd ParseFloat Issue Javascript

I have a strange issue I'm encountering only on the iPad. It seems all other browsers can handle this just fine, but I have a condition similar to this: if( parseFloat( $('#element1').css('opacity'),10).toFixed(2)!=userSetting1 || parseFloat(…
Aaron
  • 2,482
  • 1
  • 26
  • 56
1
vote
1 answer

parseFloat() usage with numbers started with 0

Im interested in why does parseFloat() return 0 in this case: var priceFromJson = '0,33'; console.log(priceFromJson); var tmpPrice = parseFloat(priceFromJson); console.log('tmpPrice'+tmpPrice); var price =…
lostika
  • 379
  • 1
  • 5
  • 15
1
vote
2 answers

Looping through objects within an array, taking total of integer values

I am trying to loop through objects within an array, adding all values with the key 'price'. var basket = [ { price: "25.00", id: "Hat" }, { price: "50.00", id: "Jacket" } ] /*objects within array.…
DVCITIS
  • 1,067
  • 3
  • 16
  • 36
0
votes
1 answer

Price value getting truncated when using jQuery parseFloat

The code is getting a price value from a hidden input field called '#orginalAddon', the cost of any additional addons is then added to this value and the result displayed to the user. The problem is that the calculated total output in '#addonPrice'…
Cronin O'M
  • 692
  • 1
  • 12
  • 19
0
votes
2 answers

My simple javascript code for parseFloat is ignoring the decimals

Here is the code: function updateCartSubtotal() { var subtotal = 0.00; $('span.item-subtotal-value').each(function () { subtotal = subtotal + parseFloat($(this).text()); //24.00 for example. }); console.log(subtotal); //…
Only Bolivian Here
  • 35,719
  • 63
  • 161
  • 257