Correct Sum?

1. Member
Join Date
Dec 1969
Posts
30

## Correct Sum?

I&#039;m trying to add a series of form fields. But for some reason it will not add decimals, like 1.5 + 1 = 2.5, but it&#039;s saying it&#039;s 2. Here is what I&#039;m doing.<BR><BR> &#060;% a = (int(SQL("day_sun")) + int(SQL("day_mon")) + int(SQL("day_tue")) + int(SQL("day_wed")) + int(SQL("day_thu")) + int(SQL("day_fri")) + int(SQL("day_sat"))) %&#062;<BR><BR>Any clue? Thank you.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Have you ANY idea...

...what the INT function does????<BR><BR>If not, then do this:<BR><BR>-- Click on VBSCRIPT REFERENCE in the left panel of this very page.<BR>-- In the list of topics that appears, click on FUNCTIONS.<BR>-- In the list of functions that appears, click on INT.<BR>-- Read.<BR><BR>Enough said?<BR>

3. Member
Join Date
Dec 1969
Posts
30

## RE: Have you ANY idea...

Honestly, I thought I could use INT to add the sums, but now I see I&#039;m incorrect. I shall search on for another function. I apologize for the question.

4. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## I assume SQL is..

.. your recordset?<BR><BR>And, if your fields are a numeric type, you shouldn&#039;t need to use any function.<BR>[code language="VBScript"]<BR>a = SQL("day_sun") + SQL("day_mon") + SQL("day_tue") + SQL("day_wed") + SQL("day_thu") + SQL("day_fri") + SQL("day_sat")<BR>[/code]

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Listen to the voice of Dog...

...errr...God. Yeah, I meant to simply get rid of the functions.<BR><BR>HOWEVER...<BR><BR>If those DB fields are DECIMAL fields, then VBScript won&#039;t be able to add them properly. In which case you want to use CDBL in place of the int you were using.<BR><BR>But try it with no functions at all, first.<BR><BR>

6. Member
Join Date
Dec 1969
Posts
30

## RE: I assume SQL is..

Thanks G for the response. Unfortunately the dummie before me built the db, and set the fields as text fields. That&#039;s why I tried to use the INT function. But it&#039;s not a biggie. I&#039;ll just require whole numbers. Thanks for looking!

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## OHHHH....

Well, then you COULD use CDBL; should work just fine.<BR><BR>But I have to ask: If you are able to "require whole numbers", then why can&#039;t you simply go change the field types in the DB, instead??? If you&#039;ve got enough authority to do the one, why don&#039;t you have enough to do the other???<BR><BR>By the by, the other possibility is to convert the values from text to numbers in the SQL query:<BR> SELECT CONVERT(DOUBLE,txt_a) AS num_a, CONVERT(DOUBLE,txt_b) AS num_b, ...<BR><BR>Probably doesn&#039;t make a whole lot of diff in performance. But truly, best would be to change the field types in the DB.<BR>

8. Member
Join Date
Dec 1969
Posts
30

## RE: OHHHH....

Thanks for the excellent feedback. First the CDBL worked great!! Thanks for the advice. I agree, I probably should just change the fields. But he&#039;s got so much code, I&#039;m scared to mess with the thing. Plus this worked great. Thanks again to both of you all.

#### Posting Permissions

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