我正在尝试从总价格中计算税款和价格,据我所知,我在下面的 PHP 和 VB.net 中创建了基本相同的代码,但我显然错过了一些东西,我现在已经花了两天时间令人尴尬的是,在大多数情况下,我得到了相同的结果,但奇怪的结果错了 1 ;
PHP 结果
DVD €11.17 €55.83
Traxdata CD-R 52X €1.09 €5.49
Aone CD-R 52X €0.56 €2.77
爱普生 18 青色 €1.04 €5.20
VB.NET 结果
DVD €11.17 €55.83
Traxdata CD-R 52X €1.10 €5.48
Aone CD-R 52X €0.56 €2.77
爱普生 18 青色 €1.04 €5.20
我已经尝试了我能想到的一切,我非常感谢任何帮助。总价格为;
DVD 67.00 欧元
Traxdata CD-R 52X €6.58
Aone 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);
}
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