Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/backendtea/safe-bc-math
Safe(r) BC Math functions for PHP
https://github.com/backendtea/safe-bc-math
Last synced: 2 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 (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-22T13:46:35.000Z (almost 5 years ago)
- Last Synced: 2024-05-02T02:43:54.468Z (9 months ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- 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);
```