Having a math problem.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Having a math problem.

  1. #1
    Join Date
    Mar 2006
    Posts
    2

    Having a math problem.

    Maybe it's because it's Friday but my mind has totally gone blank and I'm hoping that someone can help me. I need to get these two variables to add together and the just want to be combined into one long number. Can anyone see what I'm doing wrong here? Thanks for any help. I think I need a beer.
    Need a sum for val1 and val3 as stated.

    level = document.form1.level.value;
    rhr = document.form1.rhr.value;
    mhr = 220-document.form1.age.value;
    hr = mhr-rhr;
    if (document.form1.level[0].checked){
    val0 = hr * .5;
    val1 = (val0+rhr);
    val2 = hr * .64;
    val3 = (val2+rhr);

    Thanks for anything that anyone can do. I really do appreciate it.
    Cheers and happy Friday.

  2. #2
    Join Date
    Feb 2006
    Posts
    11
    Have you tried explicitly converting to a number format?
    i.e. val0 = hr.todouble() * .5;

    or something like that.

  3. #3
    Join Date
    Mar 2006
    Posts
    2
    Actually, because these numbers all depend on what the user inputs they are all variable. I need to know the value of val1 not val0. val0 is working fine it's when I get to the val1=val0+rhr that I get the problem.
    For instance if val0=65 and rhr=70, then I'm getting a value of 6570 for val1 and it really needs to be 135. What am I doing wrong?
    Thanks

  4. #4
    Join Date
    Feb 2006
    Posts
    11
    From what you just said, the problem is just what I said in my previous post. You need to convert the strings to doubles.
    (Or whatever number format you want.)

  5. #5
    Join Date
    Feb 2006
    Location
    Minnesota
    Posts
    33

    Convert from char data

    Try modifying your first two statements as shown here to force your variables to be treated as numbers:

    level = document.form1.level.value - 0;
    rhr = document.form1.rhr.value - 0;

    Don't use the addition operator, as this may simply concantenate a zero-character onto the end of the string from the form.

Similar Threads

  1. Problem with Search
    By Irina in forum ASP.NET
    Replies: 0
    Last Post: 11-29-2002, 10:47 PM
  2. Replies: 0
    Last Post: 12-13-2001, 12:06 PM
  3. a problem with font and language
    By Roseta in forum VB Classic
    Replies: 0
    Last Post: 11-14-2001, 03:24 AM
  4. Replies: 0
    Last Post: 06-23-2000, 02:17 PM
  5. Problem with CryptoAPI and JCE
    By Jason Bock in forum VB Classic
    Replies: 0
    Last Post: 03-21-2000, 06:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center