davidvandertuijn / number_format_precision
数字格式精度
1.0
2023-01-08 13:42 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2024-09-29 13:20:54 UTC
README
“数字格式精度”工具旨在为PHP中的数值格式提供精确控制,特别是针对截断小数而不进行四舍五入的需求。此功能对于需要精确数值表示的开发者非常有用,特别是在金融应用、科学计算或任何可能因四舍五入导致不准确的情况。
PHP内置函数 number_format 默认会进行四舍五入,此库则会截断小数而不进行四舍五入。
安装
composer require davidvandertuijn/number_format_precision
使用方法
使用PHP内置函数 number_format
number_format(1234.5678, 2, '.', ''); // 1234.57
使用 number_format_precision
number_format_precision(1234.5678, 2, "int")); // 1234.56 number_format_precision(1234.5678, 2, "string")); // "1234.56"