函数圆形 php 无法正常工作 [英] Function round php not work correctly

查看:53
本文介绍了函数圆形 php 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

php 函数 round 无法正常工作.我有号码 0.9950.我把代码:

php function round not working correctly. I have number 0.9950. I put code:

$num = round("0.9950", 2);

然后我得到 1.0?为什么??为什么我无法获得 0.99?

And I get 1.0? Why?? Why I can't get 0.99?

推荐答案

您可以向函数添加第三个参数,使其执行您需要的操作.您必须从以下选项之一中进行选择:

You can add a third parameter to the function to make it do what you need. You have to choose from one of the following :

  • PHP_ROUND_HALF_UP
  • PHP_ROUND_HALF_DOWN
  • PHP_ROUND_HALF_EVEN
  • PHP_ROUND_HALF_ODD

这个常量很容易理解,所以只需使用修改后的一个:)在您的示例中,要获得 0.99,您需要使用:

This constants are easy enough to understand, so just use the adapted one :) In your example, to get 0.99, you'll need to use :

<?php echo round("0.9950", 2, PHP_ROUND_HALF_DOWN); ?>

演示

这篇关于函数圆形 php 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆