davidvandertuijn/number_format_precision

1.0 2023-01-08 13:42 UTC

This package is auto-updated.

Last update: 2024-10-29 13:35:30 UTC


README

Total Downloads Latest Stable Version License

Number Format Precision

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.

"Buy Me A Coffee"

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"