bestlong 怕失憶論壇

 

 

搜索
bestlong 怕失憶論壇 論壇 Delphi TVATCalculator 含稅金額計算類別
查看: 2672|回復: 0
go

TVATCalculator 含稅金額計算類別 [複製鏈接]

Rank: 9Rank: 9Rank: 9

1#
發表於 2010-9-9 09:51 |只看該作者 |正序瀏覽 |打印
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
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw
‹ 上一主題|下一主題

Archiver|怕失憶論壇

GMT+8, 2025-5-2 06:27 , Processed in 0.017324 second(s), 12 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.