dq62957
2014-07-16 06:33
浏览 42
已采纳

echo可以指定一个浮点数吗?

I can do this using printf()

printf ("Total amount of order is %.2f", $total);

Can I do the same using echo, or I have to use printf()?

图片转代码服务由CSDN问答提供 功能建议

我可以使用printf()

printf( “订单总量是%.2f”,$ total);

我可以使用echo执行相同的操作,还是必须使用printf()?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • drpph80800 2014-07-16 06:43
    已采纳

    You can use this..

    $total= 100.123;
    echo "Total amount of order is ". round($total, 2);
    

    Output:

    Total amount of order is 100.12
    
    点赞 打赏 评论
  • doujia4759 2014-07-16 06:36

    Using echo alone? No. You would include number_format in the echoed string for the same functionality.

    echo "Total amount of order is ".number_format($total,2);
    
    点赞 打赏 评论
  • dtf54486 2014-07-16 06:36

    You cannot specify format using echo.

    However if you need to assign result to string, you can simple use sprintf function:

    $var = sprintf ("Total amount of order is %.2f", $total);
    echo $var;
    
    点赞 打赏 评论

相关推荐 更多相似问题