https://github.com/backendtea/safe-bc-math
Safe(r) BC Math functions for PHP
https://github.com/backendtea/safe-bc-math
Last synced: 11 months ago
JSON representation
Safe(r) BC Math functions for PHP
- Host: GitHub
- URL: https://github.com/backendtea/safe-bc-math
- Owner: BackEndTea
- Created: 2020-03-22T13:34:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-22T13:46:35.000Z (about 6 years ago)
- Last Synced: 2025-06-16T03:08:05.438Z (about 1 year ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Safe BC Math
## Installation
```bash
$ composer require backendtea/safe-bc-math
```
## Why this package
Casting a float to a string does not always do what you think it does.
Some locales may give unexpected results, and give a malformed string, or
the number is cast to a scientific notationm for example: `1.0E-11`. Which bcmath cant handle.
Even if you do not manually cast it to a string, the bc math functions expect strings, and will cast it themselves.
This package will throw an exception telling you what error it encountered, instead of giving a
warning `bcmath function argument is not well-formed` and returning a wrong error.
## Usage
Replace any usage of bc math functions with the `Backendtea\bc..` version.
e.g.
```diff
- bcadd($a, $b);
+ \BackEndTea\bcadd($a, $b);
```
Or even better, import the funtion:
```diff
+ use function BackEndTea\bcadd;
bcadd($a, $b);
```