PHP 浮点模数不起作用

标签 php floating-point modulus

我编写了一个函数,可以在必要时向数字添加逗号和零,但我陷入了模数函数的困境。根据我的 PHP:

float(877.5) % 1 == 0 //true

不应该877.5 % 1 == 0.5吗?

最佳答案

它提醒您您需要的分区是 fmod ,

fmod - 返回参数除法的浮点余数(模)

echo fmod(877.5, 1); // 0.5

关于PHP 浮点模数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23236851/

相关文章:

php - Virtphp 和 phpbrew : setting up two different applications with different PHP versions on one server

python - 为什么 5 != 5.0000000000000000001 为假,而 5 != 5.00000001 为真?

algorithm - 大数的模幂

c++ - float fmodf(float_x, float_y) 函数,math.h,c++

使用数据透视表具有多对多关系的 PHP Laravel 应用程序

php - 从 openssl_pkey_get_private() 检索原始私钥

.net - 缩小编码为 Base64 的 float 据字节

用于划分数字并显示数字模数的 c 程序不起作用

php - 在 codeigniter - google 登录回调 url 中包含特殊字符 (.) 并抛出 403 错误。怎么修?

c - C中的浮点常量,位表示