os0x (owner)

Revisions

gist: 207871 Download_button fork
public
Description:
4文字に収めたいときがある
Public Clone URL: git://gist.github.com/207871.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function abbr_exp_notation(count, i){
if (count < Math.pow(10, i)) {
return Math.floor(count / Math.pow(10, i-2)) + 'e' + (i-2);
} else {
return abbr_exp_notation(count, ++i);
}
}
/*
console.log([
Number(abbr_exp_notation(21,1)) === 21,
Number(abbr_exp_notation(321,2)) === 320,
Number(abbr_exp_notation(4321,3)) === 4300,
Number(abbr_exp_notation(54321,4)) === 54000,
Number(abbr_exp_notation(654321,5)) === 650000,
]);
console.log([
abbr_exp_notation(21,1) === '21e0',
abbr_exp_notation(321,2) === '32e1',
abbr_exp_notation(4321,3) === '43e2',
abbr_exp_notation(54321,4) === '54e3',
abbr_exp_notation(654321,5) === '65e4',
]);
*/