php 正确使用number_format函数以正确显示转换为哥伦比亚比索的值

0wi1tuuw  于 2023-02-07  发布在  PHP
关注(0)|答案(1)|浏览(138)

计算最终价格(含折扣),并显示转换后的哥伦比亚比索和美元值,以及函数number_format的使用

美元的处理是成功的,但哥伦比亚比索显示值不正确,但之前从美元转换为哥伦比亚比索(计算的折扣值正确,显示正确,但最终价格显示不正确)

<!-- language: lang-php-->
//COUPON_TYPE = PERCENT_AMOUNT (%)
if($row1['coupon_type'] == 'percent_value'){
                                                
echo"DCTO = ". $DiscountedValueCOP = number_format($row['p_current_price'] * $row['ValorDolarUS'] * $row1['coupon_discount'] / 100); 
                                                              
$FinalPriceValueCOP = $DiscountedValueCOP - number_format($row['p_current_price'] * $row['ValorDolarUS']); 
                                                          
//FINAL PRICE MESSAGE FOR COLOMBIAN PESO...
    
echo "Final Price Of Product" . "<br>" . "With Discount Applied: " . "<br><br>" . "$" . number_format($FinalPriceValueCOP) . "<span> <i class='flag-icon flag-icon-col'> </i> COP</span>" . "<br><br>";
}else{
    
}
<!-- end snippet -->

我需要这个结果:(现行价格)= 18.272美元COP(折扣)= 3.753美元COP =(最终价格)= 14.519美元施工制服
实际上正好是这个值= $ - 15

xdyibdwo

xdyibdwo1#

将小数位数设置为3,默认为0,作为第二个参数number_format,如下所示:

$DiscountedValueCOP = number_format($row['p_current_price'] * $row['ValorDolarUS'] * $row1['coupon_discount'] / 100, 3); 

// Final price should be current price - discount
$FinalPriceValueCOP = number_format($row['p_current_price'] * $row['ValorDolarUS'], 3) - $DiscountedValueCOP;

more about number_format

相关问题