/** * 處理數字格式(舊版,以後用 Number 取代後就移除) */ export default class NumberFormat { /** * 預設保留4為小數,不補逗點 * 範例:NumberFormat.decimal(432101050, 2, true, true) * 輸出:4,321,010.50 * * @param context * @param fixed 取得小數後幾位 * @param separator 要不要逗點 * @param floatStyle 小數位是否縮小 * @returns {*} * @constructor */ static decimal(context: string | number, fixed: number, separator?: boolean, floatStyle?: boolean): string; /** * 四捨五入 Number 資訊 * 由於Number.toFix() native 方法對於不同瀏覽器有不同實作結果,會造成精度差異以及程式bug * 例如下列程式在chrome&IE 會有不同的結果: * alert(Number(0.009).toFixed(2)); * alert(Number(162.295).toFixed(2)); * * 範例:NumberFormat.fixed(2.6) * 輸出:3 * * 範例:NumberFormat.fixed(2.6, 2) * 輸出:2.60 * * @param context 轉換數字 * @param scale 小數點位數, default:0 * @constructor */ static fixed(context: number, scale: number): string; /** * 向左補指定位數個 0 * * 範例:NumberFormat.padLeft(1, 2) * 輸出:01 * * @param context * @param length */ static padLeft(context: string, length: number): string; /** * 無條件捨去 * @param context * @param length 無條件捨去至小數第幾位 * @return {number} */ static floor(context: number, length: number): number; }