doushanmo7024 2013-09-19 12:05
浏览 20
已采纳

回声16.97没有小数位

So just like the title says, I have the need to echo out 16.97

16.97 is actually an example of a calculation done with php

I am using Stripe as my payment processor and the charge amount needs to be passed without decimal places. So 16.97 for example needs to display as 1697

Right now this is what I have and it shoots out 17 rather than 1697, I assume it is rounding.

data-amount="<?php echo number_format($grandTotal);?>" 

$grandTotal is a value set up in my php like so:

$grandTotal = $get_row['price']*$value+$get_row['shipping'];

All of these have decimal places but when I get to sending information to stripe, it doesn't need the decimal place.

I have tried multiple solutions from stackoverflow as well google and nothing worked.

So my question is what do I need to do to:

data-amount="<?php echo number_format($grandTotal);?>" 

or more specifically just number_format($grandTotal); to receive a number with no decimal places. I've read that number_format always rounds, so is there another way to do this? I hope this makes sense. If not ask questions in comments!

  • 写回答

1条回答 默认 最新

  • doujiu3768 2013-09-19 12:08
    关注

    Either multiply by 100:

    $grandTotal = $grandTotal * 100; // (moves decimal 2 places to right)
    

    or remove the periods:

    $grandTotal = str_replace('.','',$grandTotal);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部