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

Want to know reason behind NumberFormat Exception in my code

I am trying to read file with BufferedReader and at the time of spliting each line of file I want to convert string data at 8th position to be converted to float.(count starts from 0 data) below is my code : import java.io.BufferedReader; import…
Student
  • 41
  • 1
  • 6
1
vote
2 answers

Repeating javascript functions onclick

Im a total noob and need some help on a function which I would think for most of you would be quite simple. I am trying to do this with pure Javascript and not JQuery. I have been trying for hours and I cant get it. What I am trying to achieve is to…
1
vote
4 answers

Javascript parsefloat bad subtraction

I am going to subtract two floats but I get 999998.7799999999 why ? It real result is 999998.78 Money1="2,000,001.44 $"; Money2="1,000,002.66 $" Money1= Number(Money1.replace(/[^0-9\.]+/g,"")); Money2=…
Somomo1q
  • 655
  • 2
  • 10
  • 19
1
vote
2 answers

Chrome problem parsing Float from jquery css atribute

today i have a simple an understable problem for me . Next code: alphavar = $('#frontcolour').css('opacity'); console.debug(alphavar+' '+parseFloat(alphavar)); It runs ok width Firefox and width Opera ( now all perfect :) ) , but chrome i dont know…
A.Quiroga
  • 5,704
  • 6
  • 37
  • 58
1
vote
3 answers

Rounding number to two decimal places

Hy guys, I have a case where a want to round the number to exactly two decimal places. I will give an example and what I tried. Lets say I have 15.07567 To round it up I did: price = Math.round(15.07567 * 100) / 100; // and I get 15.08 But this…
Igor-Vuk
  • 3,551
  • 7
  • 30
  • 65
1
vote
1 answer

sum of floats gives no decimals in javascript

I have 2 strings that have a 0 and a 16,63 as follows: var diferencia = "0"; var estalviPotencia = "16,63"; If I put an alert to see its value with two decimals I obtain: alert(parseFloat(diferencia).toFixed(2)) -- returns…
Miquel Coll
  • 759
  • 15
  • 49
1
vote
3 answers

Adding a decimal fraction to a number using onclick() in JavaScript

I am building a calculator, and I am attempting to add a decimal to a number in JavaScript using an onclick method. So I have one function called handleNumberClick that will return any integer I click, and then have another function that should in…
1
vote
2 answers

parseFloat return 0-2.00 for -2.00

in the JavaScript I am trying to implement for my aspx page, parsefloat("-2.00') is returning a value 0-2.00 Obviously there is something I am missing out, because parsefloat can handle negative numbers, however, here it is showing me this value in…
1
vote
4 answers

Java Parsefloat Exception with a string that is number followed by characters

When I run this line of code: Float.parseFloat("1460000 JPY") I get the error Exception in thread "main" java.lang.NumberFormatException: For input string: "1460000 JPY" This string is coming from an API call from a form where this is a text field…
anton2g
  • 923
  • 6
  • 12
  • 29
1
vote
1 answer

Javascript - float value from an HTML input in table cell

It's part of the larger task. Why is the problem Nan and how to solve it? The table is added together elements from several pools which elemenatymi table. All code is summed up in the table of size k / d. Why is the problem Nan and how to…
xayos
  • 19
  • 3
1
vote
2 answers

How to use parseFloat to convert string to a number?

I was wondering how to use parseFloat with a string?. Example: var N = 3.43; var M = 43.37; var subtotal = N + M; subtotal=parseFloat("subtotal");
Nakayuma
  • 29
  • 4
1
vote
1 answer

Can you ng-init the value of ng-model based on other values on the scope?

I'm trying to calculate 2 values that the user typed in and set that result as the ng-model for another value. However I can't seem to get this code to work.
1
vote
1 answer

How to stop JavaScript removing the 0 from a number after the decimal point?

I am using JQuery to do some calculations on some items that a user selects. One of the items which is priced at £13.95, when 2 are selected gives £27.90. However, the result is always displayed as £27.9, the sum removes the last 0. How can I stop…
mickburkejnr
  • 3,652
  • 12
  • 76
  • 109
1
vote
0 answers

Highcharts Gauge (Speedometer) How to point.update PHP value

I am trying to update data field with PHP recourd using var point. Here is my PHP code: $query_Recordset1 = "SELECT * FROM table"; $Recordset1 = mysql_query($query_Recordset1, $egrid) or die(mysql_error()); $row_Recordset1 =…
BrianB
  • 133
  • 1
  • 12
1
vote
3 answers

Make parseFloat convert variables with commas into numbers

I'm trying to get parseFloat to convert a userInput (prompt) into a number. For example: var userInput = prompt("A number","5,000") function parse_float(number) { return parseFloat(number) } When userInput = 5,000, parse_Float(userInput)…
Travis
  • 1,274
  • 1
  • 16
  • 33