Add JSDoc documentation and file headers to all source files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,19 +1,29 @@
|
||||
// The Lucia project.
|
||||
// Copyright 2023-2026 DSP, inc. All rights reserved.
|
||||
// Authors:
|
||||
// chiayin.kuo@dsp.im (chiayin), 2023/1/31
|
||||
// imacat.yang@dsp.im (imacat), 2023/9/23
|
||||
// cindy.chang@dsp.im (Cindy Chang), 2024/5/30
|
||||
/** @module shortScaleNumber Short-scale number formatting. */
|
||||
|
||||
/**
|
||||
* 數量單位轉換,輸出 k m b t 數值。
|
||||
* @param {number} number 總秒數
|
||||
* @returns {string}
|
||||
* Converts a number to a short-scale abbreviated string with a suffix
|
||||
* (k for thousands, m for millions, b for billions, t for trillions).
|
||||
*
|
||||
* Values are rounded up to one decimal place.
|
||||
*
|
||||
* @param {number} number - The number to abbreviate.
|
||||
* @returns {string} The abbreviated string (e.g. "1.5k ", "2.3m ").
|
||||
*/
|
||||
export default function shortScaleNumber(number) {
|
||||
const abbreviations = ["", "k", "m", "b", "t"];
|
||||
let index = 0;
|
||||
let num = number;
|
||||
|
||||
// 確保在轉換數字時,不會超出索引範圍。如果 index 已經達到了最後一個單位縮寫(t,兆),那麼我們就不再進行轉換,以免超出數組的範圍。
|
||||
while (num >= 1000 && index < abbreviations.length - 1) {
|
||||
num /= 1000;
|
||||
index++;
|
||||
}
|
||||
// 使用 Math.ceil 來無條件進位
|
||||
num = Math.ceil(num * 10) / 10;
|
||||
return num + abbreviations[index] + " " ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user