Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatnumber

Status
Not open for further replies.

penguinspeaks

Technical User
Nov 13, 2002
234
US
Using sql db, and using asp and sql, I am having an issue.

i am storing several different int values into a db column that is set to int. now what i am trying to do, is divide one by another and have it show as a 2 decimal percentage.

the problem is when i use formatnumber, i get a mismatch error. the code is simple, but isn't working.



cont1a = food1+labor1
cont2 = formatnumber((cont1a/sales1*100), 2)

now every value in the db is int as the field type. all i am trying to do is divide and rond the decimal.

all numbers are returned correctly when called. the division works without the format number, but has a long decimal

can anyone see why this isn't working??

thanks

Bam
 
Are you dead sure that food1 and labor1 have a value (not NULL)? If one of those fields is NULL i expect a problem.

And of course sales1 is never NULL or 0 (zero divison)

 
I'm guessing that sales1 may be null.

I would use the IsNumeric() or IsNull() functions before the calculations to verify.
 
foxbox said:
And of course sales1 is never NULL or 0 (zero divison)
Actually, if sales1 is null you get a type mismatch error, not a divide by zero error.
 
you guys rock. i did find that 1 cell in the sales1 did not have a value in the loop that was null. i had to make a change in the sql retrieving the data to exclude anything that was not complete.

thanks so much guys!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top