简体   繁体   English

最有效的方法来计算PHP中的百分比

[英]Most efficient way to calculate percentage in php

i have a database with the current tax value (it is given in percentages to add like 41, 51 etc lets say it is 41 $tax = 41) The tax comes from the database the price is a post variable. 我有一个数据库,其中包含当前税值(以百分比形式给出,如41,51等等,假设它是41 $ tax = 41)税收来自数据库,价格是一个变量。

What i want to do is calcutate the new price when the tax is added. 我想要做的是在添加税时加算新价格。 Currently i have. 目前我有。

$price = 120;
$tax = 41;
$total = (($price *100 + $price * $percentage)/100);

Is there any way to make it easyer? 有没有办法让它更容易? like: 喜欢:

$total = $price * 1.$tax

i know the last one wont work but its just what i had in mind. 我知道最后一个不会工作,但它正是我的想法。

What is the best solution? 什么是最好的解决方案?

您可以在查询数据库或查询时计算百分比

$total = $price * (1 + $tax/100);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM