// import { numCapture } from "@/util/Filters.ts"; /** * 价格数据截取 * Num:截取值 * type:截取类型 (Integer:整数部分,Decimals:小数部分) */ export default { install(app, options) { console.log("Vue = ", app, options) // 添加全局方法或属性 app.config.globalProperties.numCapture = (Num : Number | String, type : 'Integer' | 'Decimals') => { let N_V = ''; const N = Num || '0.00' const N_A = String(N).split('.'); switch (type) { case "Integer": N_V = N_A[0] || '0'; break; case "Decimals": N_V = N_A[1] || '00'; break; } return N_V }; app.config.globalProperties.$addDecimals = function (num = 0, length = 8, type = true) { // length 小数的长度,type 是否需要处理 try { if (!type) { return num } let num_str = num + ""; if (num_str.indexOf('.') === -1) { num_str = `${num_str}.` for (let i = 1; i <= length; i++) { num_str += '0'; } return num_str } const numArr = num_str.split('.'); let integerNum = numArr[0], decimals = numArr[1]; if (decimals.length === length) { return num } const addLength = length - decimals.length; for (let i = 1; i <= addLength && addLength > 0 ? addLength : 0; i++) { decimals += '0' } return `${integerNum}.${decimals}` } catch (err) { return num } }; } }