473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

it won't parse float! help please

ok, i'm trying to get a return value of a float...... but it keeps giving me a load of numbers!

how do i make this interger behave?

the problem is line 39. thanks.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="javascript1.2">
  3.  
  4.  
  5. function checkreset()
  6. {
  7.  
  8.    if (confirm('Are you sure you wish to clear the form?'))
  9.    {
  10.       return true
  11.    }
  12.    return false
  13. }
  14.  
  15.  
  16. function addnumbers()
  17. {
  18.  
  19. // This function reads the values from the input boxes
  20. // parseFloat converts the input boxes into an integer
  21.  
  22. var x,y,result;
  23. a = parseFloat(document.form1.abox.value);
  24. b = parseFloat(document.form1.bbox.value);
  25. c = parseFloat(document.form1.cbox.value);
  26. d = parseFloat(document.form1.dbox.value);
  27. e = parseFloat(document.form1.ebox.value);
  28. f = parseFloat(document.form1.fbox.value);
  29. g = parseFloat(document.form1.gbox.value);
  30. h = parseFloat(document.form1.hbox.value);
  31. i = parseFloat(document.form1.ibox.value);
  32. j = parseFloat(document.form1.jbox.value);
  33.  
  34. // Then we do the math
  35.  
  36. result = a + b + c + d + e + f + g + h + i + j;
  37.  
  38. // And write the result straight to the screen
  39. document.form1.qbox.value = result;
  40. document.form1.totalbox.value = result*10.21;
  41.  
  42.  
  43. // As the function has already done the output, we don’t need a return value
  44. }
  45. </script>
  46.  
  47.  
Oct 26 '07 #1
7 2209
gits
5,390 Expert Mod 4TB
hi ...

nope ... parseFloat() handles the values as float :) ... you may use parseInt() instead ... and multiplying a float produces float again ... so you may use the math-methods to round the value

kind regards
Oct 26 '07 #2
ok, i tried math.round, and that just rounds up the number, which is no good.

so for example, instead of getting a result of €30.630000000000002, i'd like to just get a result of €30.63

how do i do this?

thanks
Oct 30 '07 #3
i'm multiplying a number by 10.21 in javascript,

Expand|Select|Wrap|Line Numbers
  1. document.form1.totalbox.value = "€" + result*10.21;
  2.  
how do i remove the extra zeros?

for example, instead of getting a result of €30.630000000000002, i'd like to just get a result of €30.63

thanks
Oct 30 '07 #4
gits
5,390 Expert Mod 4TB
use the toFixed(); method instead ...

kind regards
Oct 30 '07 #5
gits
5,390 Expert Mod 4TB
threads merged ... please don't double post questions ...

kind regards
Oct 30 '07 #6
threads merged ... please don't double post questions ...

kind regards
no worries, that worked, thanks.

Expand|Select|Wrap|Line Numbers
  1. document.form1.totalbox.value = "€" + (result*10.21).toFixed(2);
  2.  
Oct 30 '07 #7
gits
5,390 Expert Mod 4TB
:) glad to hear that ... post back to the forum anytime you have more questions

kind regards
Oct 30 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bob Rundle | last post by:
I would like to get something like this to work... Type t = FindMyType(); // might be int, float, double, etc string s = "1233"; object v = t.Parse(s); This doesn't work of couse, Parse is...
3
by: c0uch | last post by:
the first and third methods are in a usercontrol object. txtValue is a TextBox the float.parse in the if statement on line 3 always works fine. the second float.parse in the third method is...
4
by: Phil Mc | last post by:
OK this should be bread and butter, easy to do, but I seem to be going around in circles and not getting any answer to achieving this simple task. I have numbers in string format (they are...
9
by: Python.LeoJay | last post by:
Dear all, i need to parse billions of numbers from a file into float numbers for further calculation. i'm not satisfied with the speed of atof() function on my machine(i'm using visual c++ 6)....
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.