Why should you not compare floats directly for equality?

This page summarizes the projects mentioned and recommended in the original post on /r/PHP

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • Money

    PHP implementation of Fowler's Money pattern.

  • Or you can use MoneyPHP, which uses BCMath, and it takes care of all of your problems.

  • 0.30000000000000004

    Floating Point Math Examples

  • Floating point numbers, or floats, are stored as approximate binary fractions, which can cause rounding errors when compared for equality. This means that the values may not be exactly equal, leading to unexpected results. This is not specific to PHP - it is a characteristic of floating point numbers in general. Take a look: https://0.30000000000000004.com

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts