|
Calculate Tax
Home :: Classic ASP :: Number and date functions :: Calculate Tax
Here are three simple JAVASCRIPT functions you can use on active server pages to
calculate tax, gross, and Nett figures.
Why javascript for use on Active Server Pages I hear you ask? True, Vb is the default asp language,
BUT you can also use these same functions client-side in web browsers and get the exact same results. I emphasise this because
whenever you write functions that round figures Vb does it differently to Java. Bit embarrassing when we are talking money if your
javascript cart does not match what your server saves - even if it is only pennies. Believe me, I
wrote Vb versions of these functions and most of the time they gave identical results (but most of the time is not good enough).
You can easily call javascript functions on active server pages just like they were Vb from inside Vb code on active server pages so why worry?
For instance pull out some values from database tables
Or at SQL server as stored procedures:
Or client-side with Javascript
|
<%Response.Write
NettFromGross( RS("UnitPrice"), RS_Company("DefaultTaxRate") )%>
Call like this: GrossFromNett(10, 17.5)
Returns this: 11.75
Call like this: NettFromGross(10, 17.5)
Returns this: 8.51
Call like this: TaxFromGross(10, 17.5)
Returns this: 1.49
Go on, make the taxman happy!
<script LANGUAGE="javascript" RUNAT="Server">
//*****************************************************// function GrossFromNett(Nett,
TaxRate) { //USED: by a number of forms to
calculate TAX amounts //and ADD it
to NETT amount //e.g. $10 @ 17.5% =
$11.75
if (Nett !=
null);{ if (TaxRate > 0);
{ return (Nett / 100) * (100 +
TaxRate); } return
Nett; } }
//*****************************************************// function NettFromGross(Gross,
TaxRate) { //USED: by a number of forms to
calculate TAX amounts //Calculates
NETT (ExTAX) figure from GROSS //e.g.
$10 @ 17.5% = $8.51
if (Gross !=
null);{ if (TaxRate > 0);
{ return (Gross / (100 + TaxRate)) *
100; } return
Gross; } }
//*****************************************************// function TaxFromGross(Gross,
TaxRate) { //USED: by a number of forms to
calculate TAX amounts from GROSS amount //e.g. $10 @ 17.5% =
$1.49
if (Gross !=
null);{ if (TaxRate > 0);
{ var Nett = (Gross / (100 + TaxRate)) *
100; return Gross -
Nett; } return
Gross; } }
</SCRIPT>
|
Next >> Calculate Dates
|
|