473,385 Members | 1,944 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,385 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 2211
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.