davidvandertuijn / number_format_precision
Number Format Precision
1.0
2023-01-08 13:42 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2024-11-29 13:46:03 UTC
README
The “Number Format Precision” tool is designed to provide precise control over the formatting of numerical values in PHP, specifically addressing the need for truncating decimals without rounding. This functionality is particularly useful for developers who require exact numerical representation in financial applications, scientific calculations, or any scenario where rounding could lead to inaccuracies.
PHP built-in function number_format rounds by default, this library truncates decimals without rounding.
Install
composer require davidvandertuijn/number_format_precision
Usage
Using PHP built-in function number_format:
number_format(1234.5678, 2, '.', ''); // 1234.57
Using number_format_precision:
number_format_precision(1234.5678, 2, "int")); // 1234.56 number_format_precision(1234.5678, 2, "string")); // "1234.56"