doushanmo7024 2013-09-19 20: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 20:08
    关注

    Either multiply by 100:

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

    or remove the periods:

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

报告相同问题?

悬赏问题

  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?