総額から税金と価格を計算しようとしていますが、以下のPHPとVB.netで本質的に同じコードを言うことができる限り作成していますが、明らかに何かを逃した、私はこれで2日過ごしたと恥ずかしい、ほとんどの場合、私は同じ結果を得るが、奇妙なものは、例えば1で間違っています。PHPとVB.net同様のコードの異なる結果
PHPは€11.17€55.83
Traxdata CD-R 52X€1.09€5.49
青根CD-R 52X€0.56€2.77
エプソン
DVDを結果18シアン€1.04€5.20
VB.NETは€11.17€55.83
Traxdata CD-R 52X€1.10€5.48
青根CD-R 52X€0.56€2.77
エプソン
DVDを結果18シアン€1.04€5.20
私は考えることができるすべてを試したouldは本当に助けに感謝します。合計価格は以下のとおりです。
のDVD€67.00
Traxdata CD-R 52X€6.58
青根CD-R 52X€3.33
エプソン18シアン€6.24
PHP
function formatdecimalcurrency($amount) {
$multipliedNumber = $amount * 100;
$integerMultipliedNumber = floor($multipliedNumber);
$twoDecimalResult = number_format((float) ($integerMultipliedNumber/
100),2);
return $twoDecimalResult;
}
function pricefromtotal($percent, $price){
$decprice = floatval($price);
return formatdecimalcurrency($decprice - taxfromtotal($percent,
$price));
}
function taxfromtotal($percent, $price){
$decpercent = floatval($percent);
$taxasdec = $decpercent/100 + 1;
$dectotal = floatval($price);
$decprice = formatdecimalcurrency($dectotal/$taxasdec);
$dectax = $dectotal - $decprice;
return formatdecimalcurrency($dectax);
}
0英国では
VB.NET
Public Shared Function pricefromtotal(ByVal Percent As String, Price As Decimal)
Dim decprice As Decimal = CDec(Price)
Return decprice - taxfromtotal(Percent, Price)
End Function
Public Shared Function taxfromtotal(ByVal Percent As String, Price As Decimal)
Dim decpercent As Decimal
If Percent.IndexOf("%") > 0 Then
decpercent = Percent.Substring(0, Percent.Length - 1)
Else
decpercent = Percent
End If
Dim taxasdec As Decimal = decpercent/100 + 1
Dim dectotal As Decimal = CDec(Price)
Dim decprice As Decimal = MyFormatDecimalCurrency(dectotal/taxasdec)
Dim dectax As Decimal = dectotal - decprice
Return dectax
End Function
Public Shared Function MyFormatDecimalCurrency(ByVal amount As Decimal)
Dim multipliedNumber As Decimal = amount * 100
Dim integerMultipliedNumber As Decimal = Math.Round(multipliedNumber)
Dim twoDecimalResult As Decimal = FormatNumber(Convert.ToSingle(integerMultipliedNumber/100), 2)
Return twoDecimalResult
End Function
VBでは 'round'を使用しますが、PHPでは' floor'を使用します。それは1セントの違いを説明することができます。 http://php.net/manual/de/function.round.phpを試してみるか、VBコードを床に切り替えてください。 – jh1711
あなたの裁判管轄に応じて、おそらく「法律」があります。これは税金をどのように丸めなければならないかを示しています。あなたobv。両方の言語でそれを使うべきです。 – jh1711