bestlong 怕失憶論壇

標題: TVATCalculator 含稅金額計算類別 [打印本頁]

作者: bestlong    時間: 2010-9-9 09:51     標題: TVATCalculator 含稅金額計算類別

VAT or Value Added Tax is a common form of taxation in the European Union (EU). VAT is added on top of the cost of a product or service and generates revenue for a government.
  1. type TVATCalculator = class
  2. private
  3.    fVatRate: double;
  4. public
  5.    property VatRate : double read fVatRate;
  6.    constructor Create (const vatValue : double) ;

  7.    function Vat(const netValue : double) : double;
  8.    function Gross(const netValue : double) : double;
  9.    function Net(const grossValue : double) : double;
  10.    function VatFromGross(const grossValue : double) : double;
  11.    function NetFromVat(const vatValue : double) : double;
  12.    function GrossFromVat(const vatValue : double) : double;
  13. end;

  14. implementation

  15. constructor TVATCalculator.Create(const vatValue: double) ;
  16. begin
  17.    fVatRate := vatValue;
  18. end;

  19. function TVATCalculator.Gross(const netValue: double): double;
  20. begin
  21.    result := netValue + Vat(netValue) ;
  22. end;

  23. function TVATCalculator.GrossFromVat(const vatValue: double): double;
  24. begin
  25.    result := vatValue + NetFromVat(vatValue) ;
  26. end;

  27. function TVATCalculator.Net(const grossValue: double): double;
  28. begin
  29.    result := 100 / (100 + VatRate) * grossValue;
  30. end;

  31. function TVATCalculator.NetFromVat(const vatValue: double): double;
  32. begin
  33.    result := vatValue * 100 / VatRate;
  34. end;

  35. function TVATCalculator.Vat(const netValue: double): double;
  36. begin
  37.    result := VatRate * netValue / 100 ;
  38. end;

  39. function TVATCalculator.VatFromGross(const grossValue: double): double;
  40. begin
  41.    result := grossValue - Net(grossValue) ;
  42. end;
複製代碼
使用方式
  1. var
  2.    vc : TVATCalculator;
  3.    valueIn : double;
  4. begin
  5.    valueIn := StrToFloat(edValue.Text);
  6.    vc := TVATCalculator.Create(StrToFloat(edVat.Text));
  7.    try
  8.      edVat.Text := FormatFloat(',.00',vc.Vat(valueIn));
  9.      edGross.Text := FormatFloat(',.00',vc.Gross(valueIn));
  10.      edNet.Text := FormatFloat(',.00',vc.Net(valueIn));
  11.      edVatFromGross.Text := FormatFloat(',.00',vc.VatFromGross(valueIn));
  12.      edNetFromVat.Text := FormatFloat(',.00',vc.NetFromVat(valueIn));
  13.      edGrossFromVat.Text := FormatFloat(',.00',vc.GrossFromVat(valueIn));
  14.    finally
  15.      vc.Free;
  16.    end;
  17. end;
複製代碼
執行畫面

TVATCalculator-1.png

用  5% 計算 100 的結果
TVATCalculator-2.png

資料來源 http://delphi.about.com/od/delph ... -vat-calculator.htm

圖片附件: TVATCalculator-1.png (2010-9-9 09:58, 7 KB) / 下載次數 207
http://www.bestlong.idv.tw/forum.php?mod=attachment&aid=MTYxfGI1NzlkYjhmfDE3NDYxMzY3Nzh8MA%3D%3D



圖片附件: TVATCalculator-2.png (2010-9-9 09:58, 6.75 KB) / 下載次數 210
http://www.bestlong.idv.tw/forum.php?mod=attachment&aid=MTYyfDJmNDlkNDdifDE3NDYxMzY3Nzh8MA%3D%3D






歡迎光臨 bestlong 怕失憶論壇 (http://www.bestlong.idv.tw/) Powered by Discuz! X1.5