Skip to content

Instantly share code, notes, and snippets.

@ihorkatkov
Created July 22, 2015 14:32
Show Gist options
  • Save ihorkatkov/73214279e1706d7c2212 to your computer and use it in GitHub Desktop.
Save ihorkatkov/73214279e1706d7c2212 to your computer and use it in GitHub Desktop.
[JS] Получение дробной части числа
function getDecimal(num) {
var result;
var initialNum = Math.abs(num);
var roundedNum = Math.round(initialNum);
if (roundedNum > initialNum) {
result = roundedNum - initialNum - 1;
result = Math.abs(result);
result = +result.toFixed(10);
}
else {
result = initialNum - roundedNum;
result = +result.toFixed(10);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment