Answers for "comparing floats php"

PHP
0

comparing floats php

// You cannot compare float values like you would compare intergers in PHP
// since a float is calculated and may not have the exact value as shown
// an easy way to get around this is to convert the float to a string 
// for the comparison
$a = 1.5;
$b = 1.5;
if (strval($a) === strval($b)) var_dump('it matches!');
Posted by: Guest on September-21-2021

Browse Popular Code Answers by Language