|
|
 |
RE: FN-FORUM: ASP Maths Problem!
date posted 1st February 2008 11:07
Peter Wilson wrote:
> Hi All,
>
> I know it's Friday but can anyone help with this maths problem?
>
> I have a client with an online shop written in ASP, they want to add
> a 20% payable field on the checkout page. So basically you see the
> total, the vat, then the total+the vat, under this 20% of the
> total+vat
>
> This is ASP for the total:
>
>
>
> How would I take this and work out 20%?
>
> TIA
I would do something like this
dblVATRate = 17.5
intPctPayable = 20
dblVATTotal = (intTotal) + (intTotal * dblVATRate/100)
dblPayable = dblVATTotal * intPctPayable/100
Calculate the VAT total then the Payable amount into separate variables for
clarity (I am not a big fan of calculating in the output statement even
though it is less code and I personally like to split out parameters that
may change (really should be defined as constants I guess, but YMMV).
Then output as
In response to a couple of resposne posts about making 17.5/100 be 0.175, to
be fair to the original author the original more clearly states the logic as
VAT is commonly expressed as 17.5% not as 0.175 albeit they are numerically
equal. Performance difference would be negligible.
HTH,
Dai
|
 |
|