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
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern API for authentication & user identity.
  • Onboard AI - ChatGPT with full context of any GitHub repo.
  • 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

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

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