2015-07-15 12:30:11 +08:00
|
|
|
/**
|
|
|
|
* The `abbreviateNumber` utility converts a number to a shorter localized form.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* abbreviateNumber(1234);
|
|
|
|
* // "1.2K"
|
|
|
|
*
|
|
|
|
* @param {Integer} number
|
|
|
|
* @return {String}
|
|
|
|
*/
|
|
|
|
export default function abbreviateNumber(number) {
|
|
|
|
// TODO: translation
|
|
|
|
if (number >= 1000000) {
|
2015-10-20 12:04:43 +08:00
|
|
|
return Math.floor(number / 1000000) + app.translator.trans('core.lib.number_suffix.mega_text');
|
2015-07-15 12:30:11 +08:00
|
|
|
} else if (number >= 1000) {
|
2015-10-20 12:04:43 +08:00
|
|
|
return Math.floor(number / 1000) + app.translator.trans('core.lib.number_suffix.kilo_text');
|
2015-07-15 12:30:11 +08:00
|
|
|
} else {
|
|
|
|
return number.toString();
|
|
|
|
}
|
|
|
|
}
|