×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Javascript FAQ

## Applications

 Simple VAT Calculator by BigBadDave faq216-1428 Posted: 5 Jan 02 (Edited 9 Jun 02) Here is my simple VAT Calculator.Main code :function calcVat(form, field, field2, field3, vat) {  var amount = eval(document[form][field].value);  var sum = amount*vat;  var total = pound(amount+sum);  document[form][field2].value=total;  document[form][field3].value=pound(sum);  return false;}Prety simple to understand, just getting a load of variables carrying out calculations and returning results.Currency Code :function pound(num) {  var i,l,d;  var nums;  var ret;  nums = String(Math.round(num*100));  while (nums.length <3) nums = "0" + nums;  l = nums.length-3;  ret = "." + nums.charAt(l+1) + nums.charAt(l+2);  d=0;  for (i=l; i>=0; i--) {    ret = nums.charAt(i) + ret;    d++;    if (d==3 && i>0) {      ret="," + ret;      d=0;    }  }  ret = "ú" + ret;  return ret;}Again prety simple to understand just formatting output into currency formatComplete Code :            VAT Calculator

Amount :
VAT :
Total :
RegardsBig Bad Davewww.byngdesigns.co.ukdavidbyng@hotmail.com Back to Javascript FAQ Index Back to Javascript Forum

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!