LoginSignup
1
1

More than 3 years have passed since last update.

[.NET][消費税] 税込価格から本体価格を逆算する式(四捨五入/切り捨て/切り上げ)

Last updated at Posted at 2019-08-04

税込価格から本体価格を算出する方法は、消費税の端数処理方式によって異なります。
たとえば税率8%で税込価格が110円の場合、切り上げ方式で端数処理した消費税なら本体価格は101円ですが、切り捨て方式で端数処理した消費税なら本体価格は102円です。

以下、端数処理方式別の算出式です。
※rate には、0.05m, 0.08m, 0.10m などの消費税率(正の値)が入ります。

四捨五入方式で端数処理した税込価格 → 本体価格

C#
Math.Ceiling((priceWithTax - 0.5m) / (1m + rate))
VB.NET
Math.Ceiling((priceWithTax - 0.5D) / (1D + rate))

切り捨て方式で端数処理した税込価格 → 本体価格

C#
Math.Ceiling(Math.Abs(priceWithTax) / (1m + rate)) * (priceWithTax >= 0 ? 1 : -1)
VB.NET
Math.Ceiling(Math.Abs(priceWithTax) / (1D + rate)) * If(priceWithTax >= 0, 1, -1)

切り上げ方式で端数処理した税込価格 → 本体価格

C#
Math.Truncate(priceWithTax / (1m + rate))
VB.NET
Math.Truncate(priceWithTax / (1D + rate))
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1