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
3
votes
1 answer

Understanding Javascript parseFloat Behavior

Possible Duplicate: Is JavaScript’s Floating-Point Math Broken? Note - I have read other posts on parseFloat(), but I have not found a good explanation as to why the problem occurs. (Or I just didn't understand it). This code ... var sum =…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
3
votes
2 answers

Javascript casts floating point numbers to integers without cause

I wrote a function that behaves differently depending on the numeric type of it's parameters. Integer or float. Using some code from this question How do I check that a number is float or integer? it was easy to detect if float or not but then I…
naden
  • 126
  • 8
2
votes
1 answer

Javascript: prevent parseFloat from converting large number to scientific notation

I have some data in a node app which are numbers in string format. I'm trying to parse them and round off to 3 decimals by parseFloat(num).toFixed(3). Since the numbers are very large, it is automatically converting them to scientific notation (eg…
Sai Krishna
  • 593
  • 1
  • 8
  • 25
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
2 answers

.toLocaleString('fr-FR') not showing spaces in amount, but working in console

I display some prices and numbers from server with PHP, using functions to format in french. Then I want to use Jquery to do some calculations client-side. I use .toLocaleString('fr-FR') to format the results to show. It works in console but not in…
Cutis
  • 949
  • 1
  • 13
  • 32
2
votes
0 answers

Parse Datatime only show YYYY Plot.ly javascript

I've got a dataset which I am parsing into Plot.ly for use in javascript. The issue i have is that whereas my data is defined as 'yyyy-mm-dd hh:MM:ss' I only see yyyy after the parse. Wher eam i going wrong or what am i missing? My script looks…
RhinoCarl
  • 33
  • 4
2
votes
4 answers

Javascript: parseFloat not working

I am using jQuery to pull some data from a web page, it comes back as an array with the following values (.5, .25, 1.25, 3.75) which I am trying to add. Here's my code snippet: var th = 0; for (thisrow in objGrid) { var hours =…
PruitIgoe
  • 6,166
  • 16
  • 70
  • 137
2
votes
4 answers

Convert a String to float in java

I'm trying to parse a String to a float with the float.parsefloat() method but it gives me an error concerning the format. int v_CurrentPosX = Math.round(Float.parseFloat(v_posString)); //where v_posString is the float that I want to convert in this…
kazor02x
  • 43
  • 2
  • 8
2
votes
4 answers

Javascript toFixed() issues

I am having trouble with my toFixed() method. Before I added it onto all the parseFloats, which were already there, it was displaying all the totals but with too many decimal places. Now it displays nothing. When I take the toFixed() off, it…
maria
  • 41
  • 4
2
votes
1 answer

String to Float64: multiple-value strconv.ParseFloat() in single-value context

I have an array of STRING slices like this: [[header1 header2 startdate enddate header3 header4] [item1 100 01/01/2017 02/01/2017 5343340.56343 3.77252223956] [item2 554 01/01/2017 02/01/2017 22139.461201388 17.232284405]] Keep in mind that the…
shishh03
  • 57
  • 4
  • 14
2
votes
3 answers

parseFloat Doesn't Give Exact Value

I am working on a project which is require 'tip box' calculation system. As you see in the code snippet, it doesn't work as I expected. How can I solve this problem? $("select[name='tip']").on('change',function(){ var thiz = $(this); var…
oguzhancerit
  • 1,436
  • 1
  • 16
  • 27
2
votes
2 answers

use parseFloat while checking for NULL values

In AngularJS, I am trying to figure out how many hours, for a current worker, are standard vs overtime. I have a formula that works well, if the hours are integers, but fails if it has decimals. I have to account for situations where one of the…
davids
  • 5,397
  • 12
  • 57
  • 94
2
votes
3 answers

Calculator with single edittext field

I am new to android development and I am trying to develop a calculator with single edit text field. It's not showing any compiler error but it crashes as soon as I press any button. I'm first taking the input for num1 and clearing the edit text…
rishi
  • 65
  • 6
2
votes
3 answers

Float.parseFloat returns NumberFormatException that does not make sense

OK. I know that according to Java Docs: parseFloat will return a NumberFormatException - if the string does not contain a parsable float. I thought that the parseFloat method would see if the first character is a number and if it is then it will…
2
votes
3 answers

parseInt('1e1') vs parseFloat('1e1')

parseInt(1e1); //10 parseInt('1e1'); //1 parserFloat('1e1') //10 Why parseInt returns 1 in the second case? The three shouldn't return the same result?
user3798073
  • 67
  • 1
  • 7
1 2
3
14 15