Skip to content

Instantly share code, notes, and snippets.

@cho45
Last active November 16, 2015 10:35
Show Gist options
  • Save cho45/059a5aa516262828db61 to your computer and use it in GitHub Desktop.
Save cho45/059a5aa516262828db61 to your computer and use it in GitHub Desktop.
-1.6 'toFixed' '-2' 'ceil' -1 'floor' -2 'round' -2
-1.5 'toFixed' '-2' 'ceil' -1 'floor' -2 'round' -1
-1.4 'toFixed' '-1' 'ceil' -1 'floor' -2 'round' -1
-1 'toFixed' '-1' 'ceil' -1 'floor' -1 'round' -1
-0.5 'toFixed' '-1' 'ceil' -0 'floor' -1 'round' -0
-0.4 'toFixed' '-0' 'ceil' -0 'floor' -1 'round' -0
0 'toFixed' '0' 'ceil' 0 'floor' 0 'round' 0
0.4 'toFixed' '0' 'ceil' 1 'floor' 0 'round' 0
0.5 'toFixed' '1' 'ceil' 1 'floor' 0 'round' 1
1 'toFixed' '1' 'ceil' 1 'floor' 1 'round' 1
1.4 'toFixed' '1' 'ceil' 2 'floor' 1 'round' 1
1.5 'toFixed' '2' 'ceil' 2 'floor' 1 'round' 2
1.6 'toFixed' '2' 'ceil' 2 'floor' 1 'round' 2
var numbers = [
-1.6,
-1.5,
-1.4,
-1,
-0.5,
-0.4,
0,
0.4,
0.5,
1,
1.4,
1.5,
1.6
];
for (var i = 0, len = numbers.length; i < len; i++) {
var num = numbers[i];
with (Math) console.log(
num,
'toFixed', num.toFixed(),
'ceil', ceil(num),
'floor', floor(num),
'round', round(num)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment