dsnhalq37505 2015-04-11 00:22
浏览 45
已采纳

仅计算增值税的价值

I trying to calculate but can't get this done, if someone can help

I have the total of the order and the vat at 23%

 $vat = 23;

 $total = 6.00;

For add the vat to total I will do

 $total_with_vat = $total * $vat;

that will be 7.40

I now the total is 6.00, but how can I get the 1.40 of the vat

I need this to make some calculations. Looks simple but I'am not getting only to do it.

Thanks

  • 写回答

1条回答 默认 最新

  • doucong3048 2015-04-11 00:24
    关注

    Pretty simple

    $vat = $total * $vat / 100.0;
    // 1.38
    

    If you'd like to guarantee 2 digits of precision, you can use round

    $vat = round($vat, 2);
    

    Make it into a reusable function

    function calculateVat($amount, $vat=23) {
      return round($amount * $vat / 100.0, 2);
    }
    
    $amount = 6.00;
    $vat    = calculateVat($amount);
    // 1.38
    

    If VAT is a different amount, you can specify it as a second argument

    $amount = 6.00;
    $vat    = calculateVat($amount, 30);
    // 1.8
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 quartus II 9.0闪退问题怎么解决啊,急
  • ¥20 求自动化运维语料数据集
  • ¥30 广告检测流量作弊案例 IDEA运行代码报错 连接不上metastore 检测了环境配置没有问题 请求远程解决加VX问细节问题 不加的不回复
  • ¥15 matlab图像融合代码被嫌弃太简单,求改进。第一步改成直接读取三张图片,不读取文件夹
  • ¥20 微处理器原理与应用(私有偿)
  • ¥50 8051单片机关于ADC0809的应用
  • ¥15 有没有能拿来练练手写完发给我
  • ¥15 禁止修改windows系统时间
  • ¥50 kinect连接win11笔电导致音视频设备消失
  • ¥15 python线性查找题