PHPackages                             victorlap/floatval - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. victorlap/floatval

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

victorlap/floatval
==================

Correctly parse float like strings to float values

v0.1.1(4y ago)01.6k[1 issues](https://github.com/victorlap/floatval/issues)MITPHPPHP ^7.2|^8.0

Since Dec 28Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/victorlap/floatval)[ Packagist](https://packagist.org/packages/victorlap/floatval)[ Docs](https://github.com/victorlap/floatval)[ RSS](/packages/victorlap-floatval/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

floatval
========

[](#floatval)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b1fdb44ab402429c6c25ddd732af5df0ace7ad8e9623b8aad715d28f16b47465/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766963746f726c61702f666c6f617476616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/victorlap/floatval)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/31a92337695e18c44df9cdbc6bfef86af24efc1e492ad59ab33eb2f5479d1f88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766963746f726c61702f666c6f617476616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/victorlap/floatval)

Correctly parse float like strings to float values. This library is based on the `tofloat` function originally from  .

Install
-------

[](#install)

Via Composer

```
$ composer require victorlap/floatval
```

Usage
-----

[](#usage)

```
$float = Victorlap\Floatval::parse('123,456');
```

Warning about Floating point precision
--------------------------------------

[](#warning-about-floating-point-precision)

The default warnings apply when working with floating point numbers. Quoted from php.net:

> Floating point numbers have limited precision. Although it depends on the system, PHP typically uses the IEEE 754 double precision format, which will give a maximum relative error due to rounding in the order of 1.11e-16. Non elementary arithmetic operations may give larger errors, and, of course, error propagation must be considered when several operations are compounded.
>
> Additionally, rational numbers that are exactly representable as floating point numbers in base 10, like `0.1` or `0.7`, do not have an exact representation as floating point numbers in base 2, which is used internally, no matter the size of the mantissa. Hence, they cannot be converted into their internal binary counterparts without a small loss of precision. This can lead to confusing results: for example, `floor((0.1+0.7)*10)` will usually return `7` instead of the expected 8, since the internal representation will be something like `7.9999999999999991118...`.
>
> So never trust floating number results to the last digit, and do not compare floating point numbers directly for equality. If higher precision is necessary, the [arbitrary precision math functions](https://www.php.net/manual/en/ref.bc.php) and [gmp](https://www.php.net/manual/en/ref.gmp.php) functions are available.
>
> For a "simple" explanation, see the [» floating point guide](http://floating-point-gui.de/) that's also titled "Why don’t my numbers add up?"

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Victor Lap](https://github.com/victorlap)
- [Gaabora](http://codepad.org/users/gaabora)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance41

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~318 days

Total

2

Last Release

1684d ago

PHP version history (2 changes)v0.1.0PHP ~7.2

v0.1.1PHP ^7.2|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1645632?v=4)[Victor](/maintainers/victorlap)[@victorlap](https://github.com/victorlap)

---

Top Contributors

[![victorlap](https://avatars.githubusercontent.com/u/1645632?v=4)](https://github.com/victorlap "victorlap (8 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (2 commits)")

---

Tags

floatvalvictorlap

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/victorlap-floatval/health.svg)

```
[![Health](https://phpackages.com/badges/victorlap-floatval/health.svg)](https://phpackages.com/packages/victorlap-floatval)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[karriere/json-decoder

JsonDecoder implementation that allows you to convert your JSON data into PHP class objects

140439.4k12](/packages/karriere-json-decoder)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[json-mapper/laravel-package

The JsonMapper package for Laravel

25188.9k3](/packages/json-mapper-laravel-package)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
