Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

take fraction of number in laravel

$price = 350.32;

$whole = intval($price); // 350
$decimal1 = $price - $whole; // 0.3200000000005 
$decimal2 = round($decimal1, 2); // 0.32 this will round off the excess numbers
$decimal = substr($decimal2, 2); // 32 this removed the first 2 characters

if ($decimal == 1) { $decimal = 10; } 
if ($decimal == 2) { $decimal = 20; } 
if ($decimal == 3) { $decimal = 30; }  
if ($decimal == 4) { $decimal = 40; }
if ($decimal == 5) { $decimal = 50; }
if ($decimal == 6) { $decimal = 60; }
if ($decimal == 7) { $decimal = 70; }
if ($decimal == 8) { $decimal = 80; }
if ($decimal == 9) { $decimal = 90; }
 
PREVIOUS NEXT
Tagged: #fraction #number #laravel
ADD COMMENT
Topic
Name
5+7 =