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
111
votes
10 answers

Javascript parse float is ignoring the decimals after my comma

Here's a simple scenario. I want to show the subtraction of two values show on my site: //Value on my websites HTML is: "75,00" var fullcost = parseFloat($("#fullcost").text()); //Value on my websites HTML is: "0,03" var auctioncost =…
Only Bolivian Here
  • 35,719
  • 63
  • 161
  • 257
55
votes
8 answers

Is NaN equal to NaN?

parseFloat("NaN") returns "NaN", but parseFloat("NaN") == "NaN" returns false. Now, that's probably a good thing that it does return false, but I don't understand how this is so. Did the JavaScript creators just make this a special case? Because…
joseph
  • 767
  • 3
  • 8
  • 16
51
votes
5 answers

parseFloat rounding

I have javascript function that automatically adds input fields together, but adding numbers like 1.35 + 1.35 + 1.35 gives me an output of 4.050000000000001, just as an example. How can I round the total to the second decimal instead of that long…
JB.
  • 893
  • 3
  • 16
  • 29
39
votes
7 answers

javascript parseFloat '500,000' returns 500 when I need 500000

How would it be a nice way of handling this? I already thought on removing the comma and then parsing to float. Do you know a better/cleaner way? Thanks
DanC
  • 8,595
  • 9
  • 42
  • 64
21
votes
3 answers

Second argument to parseFloat in JavaScript?

In this font-size resizing tutorial: Quick and easy font resizing the author uses parseFloat with a second argument, which I read here: parseFloat() w/two args Is supposed to specify the base of the supplied number-as-string, so that you can…
AmbroseChapel
  • 11,957
  • 7
  • 46
  • 68
18
votes
4 answers

How can I move the decimal point to the 100ths of an integer?

This seems like a silly question but I cant figure out how to convert an integer number that represent cents to dollars. 3000 -> 30.00 in javascript... I was using ParseFloat but it's only giving me back the integer =/ I need to always display the…
qodeninja
  • 10,946
  • 30
  • 98
  • 152
13
votes
3 answers

Is it possible to parseFloat the whole string?

As you know, the javascript's parseFloat function works only until it meets an invalid character, so for example parseFloat("10.123") = 10.123 parseFloat("12=zzzz") = 12 parseFloat("z12") = NaN Is there a way or an implementation of parseFloat that…
mcm69
  • 670
  • 6
  • 14
11
votes
4 answers

React onChange is swallowing my decimal when using parseFloat

I have a simple onChange which takes the user's input pareses it and sets the state to render. Here is the code. import React, { Component } from 'react'; import './App.css'; class App extends Component { constructor() { super(); …
Chaim Friedman
  • 6,124
  • 4
  • 33
  • 61
11
votes
5 answers

ParseFloat function in JavaScript

When I am adding two textbox values that are 1.001 and 0.001 and then I do a parseFloat I get 1.0019999999. I want it 1.002 . Can you help me?
Aarti Jain
11
votes
2 answers

Display numbers up to two decimals places without trailing zeros

In my code I will be accepting multiple values, for example: 8.7456 8.7 8 and I need to have them appear as 8.74 8.7 8 i.e. display up to two decimal place. I understand that .toFixed(2) will help me with the first value, but on the 2nd and 3rd…
peroija
  • 1,982
  • 4
  • 21
  • 37
10
votes
5 answers

test if a string is a valid float in JavaScript

I want to test if a string can be cast as a float. I have been trying to use parseFloat to achieve this. console.log(!isNaN(parseFloat("10000"))); // should return true console.log(!isNaN(parseFloat("100T0"))); // should return false (but…
rvictordelta
  • 630
  • 2
  • 8
  • 23
10
votes
3 answers

Javascript parseFloat '1.23e-7' gives 1.23e-7 when need 0.000000123

parseFloat(1.51e-6); // returns 0.00000151 parseFloat(1.23e-7); // returns 1.23e-7 // required 0.000000123 I am sorting table columns containing a wide range of floating-point numbers, some represented in scientific notation. I am using the jQuery…
shanesolo
  • 141
  • 1
  • 1
  • 6
10
votes
1 answer

Converting string input to float64 using ParseFloat in Golang

I've just started learning Go and I'm trying to convert a string from standard input to a float64 so I can perform an arithmetic operation on the input value. The output returns "0 feet converted to meters gives you 0 meters" regardless of the input…
efettero
  • 103
  • 1
  • 1
  • 6
9
votes
1 answer

How to round off parseFloat results in Jquery/Javascript?

How would I round off a value from a textfield with a parseFloat result in it? This application basically sums up the value of all radio buttons when clicked and displays the sum in a textbox. The code below works perfectly if the radio button value…
Davinchie_214
  • 155
  • 2
  • 2
  • 6
9
votes
3 answers

Parse Float has a rounding limit? How can I fix this?

I set up a system that parses a compact data string into JSON. I'm using a 19 digit number to store ids. Unfortunately any number greater than 17 digits, parseFloat() rounds the last few digits. This breaks the whole data string. Can I fix this? For…
Robert Hurst
  • 8,902
  • 5
  • 42
  • 66
1
2 3
14 15