Created
February 5, 2020 09:20
-
-
Save moshiurse/a27a0c8a8cf75d53dcd11405e666d90b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function unit_converter($value, $precession, $lvl1, $lvl2){ | |
$level1 = ""; | |
$level2 = ""; | |
$level3 = ""; | |
$rem = ""; | |
$formatedUnit = ""; | |
if($lvl1 && $lvl1 > 0){ | |
$level3 = $value % $lvl1; | |
$rem = intval($value / $lvl1); | |
$formatedUnit = $rem . "-". $level3; | |
}else{ | |
if($precession){ | |
return number_format($value, $precession); | |
}else{ | |
return $value; | |
} | |
} | |
if($lvl2 && $lvl2 > 0){ | |
$level2 = $rem % $lvl1; | |
$level1 = intval($rem / $lvl1); | |
$formatedUnit = $level1. "-" . $level2 . "-" . $level3; | |
} | |
return $formatedUnit; | |
} | |
echo unit_converter(506,2, 12,12); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment