PHP和VB.net类似的代码结果不同

时间:2017-08-11 01:15:29

标签: php vb.net tax

我试图从总价中计算税收和价格,我已经创建了基本相同的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

     

Epson 18 Cyan€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

     

Epson 18 Cyan€1.04€5.20

我已经尝试了我能想到的一切,我真的很感激任何帮助。总价格是;

  

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

1 个答案:

答案 0 :(得分:0)

在英国,你可以向上或向下,对不起我实际上有数学。地板,但我在那里进行实验时更改了它们,它们都给出了相同的结果

编辑:设法通过转换为vb.net中的整数来对其进行排序