dpsfay2510 2017-08-01 22:17
浏览 28
已采纳

在sprintf中添加变量之间的间隔

I've got this code snippet:

$format = '%s' . $format;
return sprintf($format, number_format((double)$amount, $decimal, $decimal_point, $thousand_sep), $currency);

I would like to add an interval/blank space that would show up between number_format and $currency. Can you tell me how this could be achieved? Thank you.

  • 写回答

1条回答 默认 最新

  • dqpd4268 2017-08-01 22:24
    关注

    I'm not 100% sure what you're trying to do, but it looks like you want to format your string like this:

    $format = '%s %s';
    return sprintf($format, number_format((double)$amount, $decimal, $decimal_point, $thousand_sep), $currency);
    

    PS: I don't know where the $format = '%s' . $format; came from, as you haven't specified what value $format was assigned to before that statement.

    Also, it can't hurt to read: http://php.net/manual/en/function.sprintf.php

    EDIT: if the number_format() function returns a double change $format = '%s %s'; to $format = '%g %s';

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题