PHPackages                             roave/no-floaters - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. roave/no-floaters

ActivePhpstan-extension[Validation &amp; Sanitization](/categories/validation)

roave/no-floaters
=================

PHPStan Rules to Disallow Float proliferation in contexts where IEEE-754 rounding errors are not acceptable

1.16.0(3w ago)216335.7k—2.6%13[2 issues](https://github.com/Roave/no-floaters/issues)[2 PRs](https://github.com/Roave/no-floaters/pulls)18MITPHPPHP ~8.4.0 || ~8.5.0CI failing

Since Jan 9Pushed 1w ago4 watchersCompare

[ Source](https://github.com/Roave/no-floaters)[ Packagist](https://packagist.org/packages/roave/no-floaters)[ Fund](https://tidelift.com/funding/github/packagist/roave/no-floaters)[ RSS](/packages/roave-no-floaters/feed)WikiDiscussions 1.17.x Synced 1w ago

READMEChangelog (10)Dependencies (22)Versions (37)Used By (18)

roave/no-floaters
=================

[](#roaveno-floaters)

[![roave/no-floaters](logo/roave-no-floaters.png)](logo/roave-no-floaters.png)

[![Latest Stable Version](https://camo.githubusercontent.com/edef18394f8f64a577cc71597753818176e6602ed46ce1fbfa34038d14bb9e2d/68747470733a2f2f706f7365722e707567782e6f72672f726f6176652f6e6f2d666c6f61746572732f762f737461626c652e706e67)](https://packagist.org/packages/roave/no-floaters)

This library is a [PHPStan](https://github.com/phpstan/phpstan) plugin that disallows:

- declaration of `float` properties
- `float` method parameters
- `float` method return types
- assignment of `float` values to variables or properties

The reason for this restriction is that rounding errors coming from floating point arithmetic operations are not acceptable in certain business logic scenario, such as dealing with money, evaluating exam results, rocket science, etc.

An example of such problems can be seen with the following typical [example](https://3v4l.org/MJqJe):

```
var_dump((0.7 + 0.1) === 0.8); // output: bool(false)
```

This can mean no trouble at all, or a lot of trouble, depending on how many numbers you are running through your system, so it is advisable to avoid `float` for domains where rounding can potentially lead to trouble.

`float` is still perfectly acceptable in many programming contexts, and this ruleset should only be applied where it is critical not to introduce rounding errors.

Installation
------------

[](#installation)

```
composer require --dev roave/no-floaters
```

Configuration
-------------

[](#configuration)

In your `phpstan.neon` configuration, add following section:

```
includes:
    - vendor/roave/no-floaters/rules.neon
```

Optionally, you can configure the library to disallow any `float`-producing expression at all, by adding following to your `phpstan.neon`:

```
parameters:
    disallowFloatsEverywhere: true
```

If the above is enabled, given the following `example-file.php`contents:

```
