Skip to content

Instantly share code, notes, and snippets.

@moshiurse
Created February 5, 2020 04:54
Show Gist options
  • Save moshiurse/bbe8b0721df97e93ad883a160d8c1fd8 to your computer and use it in GitHub Desktop.
Save moshiurse/bbe8b0721df97e93ad883a160d8c1fd8 to your computer and use it in GitHub Desktop.
function unitConverter(value, precession, lvl1, lvl2){
var level1,level2,level3, rem, formatedUnit;
if(lvl1 && lvl1 > 0){
level3 = value % lvl1;
rem = parseInt(value /lvl1);
formatedUnit = rem + "-"+ level3;
}else{
if(precession){
return value.toFixed(precession);
}else{
return value;
}
}
if(lvl2 && lvl2 > 0){
level2 = rem % lvl1;
level1 = parseInt(rem / lvl1);
formatedUnit = level1+ "-" + level2 + "-"+ level3;
}
return formatedUnit;
}
unitConverter(506,0, 0,12);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment