Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
浮動小数の比較にイプシロンを使用するのではなく、2 つの浮動小数点数を目的の精度に丸めることで、同等性を確実に比較できますか?
例えば:
round($float, 3) === round($otherFloat, 3)
いいえ。数値が、関数が切り捨てではなく切り上げられる値の反対側にある場合 (最も近い整数に丸める場合は半整数)、どれだけ近い値であっても、異なる数値に丸められます。一緒です。