J'essaie de calculer la taxe et le prix d'un prix total, j'ai créé autant que je peux dire essentiellement le même code en PHP et VB.net ci-dessous mais j'ai évidemment manqué quelque chose, j'ai passé deux jours là-dessus maintenant et c'est embarrassant, pour la plupart j'obtiens les mêmes résultats mais l'impair est faux par 1 par exemple;PHP et VB.net code similaire résultats différents
PHP Résultats
DVD € 11,17 € 55,83
Traxdata CD-R 52X € 1,09 € 5,49
Aone CD-R 52X € 0,56 € 2,77
Epson 18 Cyan € 1,04 € 5,20
VB.NET Résultats
DVD € 11,17 € 55,83
Traxdata CD-R 52X € 1,10 € 5,48
Aone CD-R 52X € 0,56 € 2,77
Epson 18 Cyan € 1,04 € 5,20
J'ai essayé tout ce que je peux penser, je w J'apprécierais vraiment toute aide. Les prix totaux sont;
DVD € 67,00
Traxdata CD-R 52X € 6,58
Aone CD-R 52X € 3,33
Epson 18 cyan € 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
Vous utilisez 'round' dans VB, mais' floor' dans PHP. Cela pourrait expliquer la différence de 1 cent. Essayez http://php.net/manual/de/function.round.php, ou passez le code VB à l'étage. – jh1711
Selon votre juridiction, il y a probablement une «loi», qui vous indique comment vous devez arrondir les taxes. Vous obv. devrait utiliser cela pour les deux langues. – jh1711