Answers for "double vs float php"

PHP
3

php float value

floatval ($var)
Posted by: Guest on June-19-2019
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 round the float, then convert the float
//to a string for the comparison
$a = 1.5;
$b = 1.5;
$a = round($a, 2);
$b = round($b, 2);
if (strval($a) === strval($b)) var_dump('it matches!');
Posted by: Guest on September-21-2021

Browse Popular Code Answers by Language