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
2
votes
2 answers

Splitting an array of strings to an array of floats in JavaScript

I am trying to split an array of strings, called 'vertices' and store it as an array of floats. Currently the array of strings contains three elemets: ["0 1 0", "1 -1 0", '-1 -1 0"] What I need is an array of floats containing all these digits as…
petehallw
  • 1,014
  • 6
  • 21
  • 49
2
votes
1 answer

ParseFloat array values

I'm trying to parse the values in my array then add them to a chart. Problem is I'm getting some unexpected numbers on the out put. I loop through and populate my array. On the button click I loop through and parse the data and put it into…
Troy Bryant
  • 994
  • 8
  • 29
  • 60
2
votes
1 answer

Why does jsperf give different results based on preparation code in HTML vs setup?

I was trying to see which methods of converting a string to a number in javascript are more performant, so I went to jsperf to see what might work best. However, I seem to be getting different results based on whether or not the initial variables…
2
votes
6 answers

how to truncate the float value in javascript

We want to display dynamic value in a table using JavaScript in vb.net. we have define the variable as var rValue. The expression is rValue = parseFloat(594 * 0.1); We are getting putput as 59.400000000000006 but we need the output as 59.4 please…
user3530807
  • 19
  • 1
  • 4
2
votes
1 answer

parseFloat bug in IE

It seems a very simple question. the result of parseFloat in IE is different from the results in Chrome and FF. Here is the very simple code
user3416285
  • 25
  • 1
  • 5
2
votes
1 answer

Javascript parseFloat changes number

I'm trying to convert "9999999999999099" into a number/float in javascript. The problem is that both parseFloat(X) and Number(X) return 9999999999999100. This is not the same number. Does anyone know why this happens and how to avoid it? Thanks in…
cattox
  • 177
  • 2
  • 16
2
votes
2 answers

Using toFixed(2) in JavaScript is producing undesired results

I'm doing this: var refundAmount = parseFloat($('#refundAmount2').val().replace('$','')); var refundReceived = $('#refundReceived'); var remainderAmount =…
Damien
  • 4,093
  • 9
  • 39
  • 52
2
votes
2 answers

parseFloat function does not work as expected

I need to validate textbox entry. It should allow only integers as entityframework fails if user enters characters in this field during binding. Here is problem: When user enters 10-d in this field, parseFloat returns true as it takes 10 as number…
PL0689
  • 21
  • 5
1
vote
1 answer

I am having an issue correctly appending decimal pointers in my small Basic Calculator App

In my basic calculator app, I'm experiencing a problem with correctly appending decimal points. When I input a number like 2.5 and then try to perform a calculation, the decimal point disappears, resulting in the number being interpreted as 25…
1
vote
2 answers

Convert a string into a number keeping the commas in js

is there any way to convert a string like "7,1" into a number and keep the commas after the conversion?. I've tried parseInt but that will ignore everything after the first value. Is there another way around it?
willd
  • 119
  • 1
  • 6
1
vote
2 answers

For float num with 0-2 decimals, if x+y=z in decimal and MIN_VALUE<=x,y,z<=MAX_VALUE, is Number.parseFloat((x+y).toFixed(2))==z always true?

For example, I know 0.1+0.2 == 0.3 is false because float number is not accurate sometimes. After adding toFixed(2) following Number.parseFloat, it becomes true: console.log(0.1+0.2 ==…
1
vote
0 answers

javascript basic calculation price,quantity and discount

I would like to count price and discount and quantity for result which is the total. Is it possible to do with javascript and how? I have tried several ways to implement the function in javascript however none of my effort works.
tony
  • 11
  • 1
1
vote
5 answers

Why do I keep getting Nan even though I am using parseFloat function?

For some reason I keep getting Nan when I am trying to convert Kms to Miles. It seems like the parseFloat function isn't working. Any ideas what can be that I am not seeing? document.querySelector('button').onclick = function(){ let…
1
vote
1 answer

While adding two numbers getting NAN as output in the react?

When I am trying to add two numbers, I am able to get NaN. If anyone has any advice, any help would be greatly appreciated. This is my Code:- var sum = parseInt(label.labellength, 10) + parseInt(label.labely, 10); console.log("Sum of FrontRight…
Bikram
  • 33
  • 4
1
vote
0 answers

parseFloat is giving NaN

HTML code:

Javascript code: let iop=document.getElementById('iop').value; let num=parseFloat(iop); function suh(){ …