
Setting Up a Numeric Value
I'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've tried "Discount = 0 + 0".<BR><BR>My Final Price is calculated as "FinalPrice = rsMembership.Fields.Item("mpPrice").Value  Discount". But, If I don'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

two ways to do that...
1) Use CDbl on Discount to convert it to a type double<BR>2) Use a IFTHENELSE 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

RE: Setting Up a Numeric Value
Not real pretty but...<BR><BR> Decimal = Int(0.1)<BR><BR>

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.

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)

RE: Discount = Int(0.1) ... No Luck
Okay...<BR>Try an IF<BR>example I couldn't remember the original message<BR>IF rs.EOF Then ' rs is the recordset with the discount<BR> finalprice = value * 0.0<BR>else<BR> finalprice = value * discount<BR>End if

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

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.

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><%<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>%>

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

Forum Rules

