Skip to content

Instantly share code, notes, and snippets.

@moshiurse
Created February 5, 2020 09:20
Show Gist options
  • Save moshiurse/a27a0c8a8cf75d53dcd11405e666d90b to your computer and use it in GitHub Desktop.
Save moshiurse/a27a0c8a8cf75d53dcd11405e666d90b to your computer and use it in GitHub Desktop.
<?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