dpqjvoq9033 2017-09-22 16:47
浏览 39
已采纳

PHP使用十进制乘以货币变量

I'm trying to multiply a variable by a decimal (percentage) but it's outputting 0 as the value. The variable has a dollar sign and two decimal places ($53,900.00).

$baseprice = $53,900.00;
$ott = .92;
echo ($baseprice * $ott);

I think the currency sign ($) is messing it up. Can someone help?

  • 写回答

2条回答 默认 最新

  • dongxiezhi0590 2017-09-22 17:00
    关注

    You can also use the money_format() function to print it out with the dollar sign and comma. But when you declare a variable as a number it can't contain commas ',' or '$' or it gets cast to a string. Here is an example of using money_format.

    $baseprice = 53900.00;
    $ott = .92;
    echo money_format('%n',($baseprice * $ott)); # prints $49,588.00    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应