Having a math problem.

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Having a math problem.

1. Registered User
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. Registered User
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. Registered User
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. Registered User
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. Registered User
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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise