diff --git a/components/Format.js b/components/Format.js index 998e223b..3a09d073 100644 --- a/components/Format.js +++ b/components/Format.js @@ -1,5 +1,6 @@ import lodash from 'lodash' import Elem from './common-lib/elem.js' +import { Cfg } from '../components/index.js' let Format = { ...Elem, @@ -9,7 +10,8 @@ let Format = { comma: function (num, fix = 0) { num = parseFloat((num * 1).toFixed(fix)) let [integer, decimal] = String.prototype.split.call(num, '.') - integer = integer.replace(/\d(?=(\d{3})+$)/g, '$&,') // 正则先行断言 + let re = new RegExp(`\\d(?=(\\d{${Cfg.get('commaGroup', 3)}})+$)`, 'g') + integer = integer.replace(re, '$&,') // 正则先行断言 = /\d(?=(\d{3})+$)/g return `${integer}${fix > 0 ? '.' + (decimal || lodash.repeat('0', fix)) : ''}` }, pct: function (num, fix = 1) { diff --git a/config/cfg_default.js b/config/cfg_default.js index 16716bd1..c0b78c71 100644 --- a/config/cfg_default.js +++ b/config/cfg_default.js @@ -17,6 +17,9 @@ export const avatarWife = true // 戳一戳卡片 export const avatarPoke = true +// 数字分组 +export const commaGroup = 3 + /** ************ 【角色资料与信息查询】 ************* */ // #刻晴图鉴 的图鉴信息 export const charWiki = true diff --git a/config/system/cfg_system.js b/config/system/cfg_system.js index 096d3659..ec69aed3 100644 --- a/config/system/cfg_system.js +++ b/config/system/cfg_system.js @@ -47,7 +47,14 @@ export const cfgSchema = { key: '戳一戳', def: true, oldCfgKey: 'char.poke' - } + }, + commaGroup: { + title: '数字逗号分组', + key: '逗号', + def: 3, + type: 'num', + desc: '根据语言习惯设置数字分组,如千位组设为 3,万位组设为 4。(暂不支持欧洲样式)' + }, } }, wiki: {