Setting Up a Numeric Value

# Thread: Setting Up a Numeric Value

1. Senior Member
Join Date
Dec 1969
Posts
102

## Setting Up a Numeric Value

I&#039;m trying to perform a math function on a value. I have a Price from a mySQL Table defined as Decimal(6, 2). I am trying to get a Discount from a Promo Table defined as Decimal(6, 2). I am trying to set up the Discount amount to 0 before I try to get the PromoCode. I use "Discount = 0", I&#039;ve tried "Discount = 0 + 0".<BR><BR>My Final Price is calculated as "FinalPrice = rsMembership.Fields.Item("mpPrice").Value - Discount". But, If I don&#039;t get a hit on the DB, I get a "Type MisMatch" on the calculation.<BR><BR>How can I Make the Discount a Numeric Value of 0?<BR><BR>Thanx,<BR>Lou

2. Senior Member
Join Date
Dec 1969
Posts
2,334

## two ways to do that...

1) Use CDbl on Discount to convert it to a type double<BR>2) Use a IF-THEN-ELSE statement to conditionally execute the Calculate FinalPrice statement.<BR><BR>If NOT rsMembership.eof Then<BR> FinalPrice = rsMembership.Fields.Item("mpPrice").Value - Discount<BR>End If

3. Junior Member
Join Date
Dec 1969
Posts
4

## RE: Setting Up a Numeric Value

Not real pretty but...<BR><BR> Decimal = Int(0.1)<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
102

## I just Tried the CDbl.....No Luck

I used it as:<BR><BR>Discount = CDbl(0)<BR><BR>and when I display it, it comes out as 0 and the price (decimal(6,2)) comes out as 69.95.<BR><BR>I still get the MisMatch.

5. Senior Member
Join Date
Dec 1969
Posts
102

## Discount = Int(0.1) ... No Luck

I Just tried this, but I still get the MisMatch.<BR><BR>I think the Discount needs to be Decimal(6, 2)

6. Junior Member
Join Date
Dec 1969
Posts
4

## RE: Discount = Int(0.1) ... No Luck

Okay...<BR>Try an IF<BR>example I couldn&#039;t remember the original message<BR>IF rs.EOF Then &#039; rs is the recordset with the discount<BR> finalprice = value * 0.0<BR>else<BR> finalprice = value * discount<BR>End if

7. Senior Member
Join Date
Dec 1969
Posts
2,334

## how are you getting the value of discount

From a recordet??<BR><BR>Then do this.<BR><BR>FinalPrice = CDbl(FirstVar) - CDbl(SecondVar)<BR><BR>But anyway before doing that MATHS you should check if the recordset is empty or not. So you must check for EOF.<BR><BR>FinalPrice = rsMembership.Fields.Item("mpPrice").Value - Discount

8. Senior Member
Join Date
Dec 1969
Posts
102

## I found the "FormatNumber" Function in the FAQ Sec

I found the FormatNumber Function to make my Initial Value of Discount to have 2 decimal places.<BR><BR>Discount = FormatNumber(0, 2)<BR><BR>This seems to work.

9. Senior Member
Join Date
Dec 1969
Posts
2,493

## RE: Setting Up a Numeric Value

Am I missing something here<BR><BR>both of the below give me a result of \$62.40<BR><BR>&#060;%<BR>Price= 62.50<BR>Discount = 0.10<BR><BR>response.write formatCurrency(Cdbl(Price) - Cdbl(Discount))<BR><BR>response.write formatCurrency(Price - Discount)<BR>%&#062;

10. Senior Member
Join Date
Dec 1969
Posts
2,334

## what happens if you

only do...<BR>response.write (Cdbl(Price) - Cdbl(Discount)) <BR><BR>response.write (Price - Discount)

#### Posting Permissions

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