Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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!');
Comment

PREVIOUS NEXT
Code Example
Php :: php remove html tag 
Php :: php check session status 
Php :: php replace string within string 
Php :: mysqli_real_connect(): (HY000/2002): No such file or directory 
Php :: php get looping month 
Php :: factorial function php 
Php :: artisan 
Php :: xamp to test on mobile 
Php :: convert array to stdclass object in php example 
Php :: remove product from cart by id woocommerce 
Php :: carbon now 
Php :: php replace first occurrence in string 
Php :: format seconds to human readable carbon 
Php :: laravel 8 make model with migration and controller 
Php :: how to get last id in database 
Php :: changing created_at to short date time 
Php :: php cheatsheet 
Php :: laravel observer events 
Php :: php print_r 
Php :: how to retrieve image from database in php mysqli 
Php :: laravel validation unique email except self 
Php :: full month name php 
Php :: multiple selected checkbox values in database 
Php :: Displaying the category name of a custom post type 
Php :: php convert to string 
Php :: autogenerate slug for model laravel 
Php :: mysqli fetch row assoc 
Php :: wherejsoncontains laravel 
Php :: laravel order by numbers 
Php :: Remove the Breadcrumbs on the Shop Entirely 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =