function division(compare: any, groupingRule: string, thousandsSep: string): string {
return compare.replace(new RegExp('(\\d)(?=(?:\\d{' + groupingRule + '})+$)', 'g'), '$1' + thousandsSep);
}
1.--------------const convertGroupRuleValue = (basicsConfig: IFloatConfig, initialValue: string): string => {
if(!initialValue) {
return initialValue
}
let val = (initialValue).toString();
const { decimalPoint, groupingRule, thousandsSep } = basicsConfig
if(!groupingRule || !thousandsSep) {
return val
}
let pointValue = val.split('.');
if (decimalPoint) {
return val.indexOf(decimalPoint) != -1 ? division(val.split(decimalPoint)[0], groupingRule, thousandsSep) + decimalPoint + val.split(decimalPoint)[1] :
division(pointValue[0], groupingRule, thousandsSep)
}
return val.indexOf('.') != -1 ? division(pointValue[0], groupingRule, thousandsSep) + '.' + pointValue[1] :
division(val, groupingRule, thousandsSep)
}
2.-------
// const convertGroupRuleValue = (basicsConfig: IFloatConfig, initialValue: string): string => {
// if (initialValue) {
// let val = (initialValue).toString();
// const { decimalPoint, groupingRule, thousandsSep } = basicsConfig
// if (groupingRule && thousandsSep) {
// let pointValue = val.split('.');
// if (decimalPoint) {
// if (val.indexOf(decimalPoint) != -1) {
// return division(val.split(decimalPoint)[0], groupingRule, thousandsSep) + decimalPoint + val.split(decimalPoint)[1]
// }
// return division(pointValue[0], groupingRule, thousandsSep)
// }
// if (val.indexOf('.') != -1) {
// return division(pointValue[0], groupingRule, thousandsSep) + '.' + pointValue[1];
// }
// return division(val, groupingRule, thousandsSep)
// }
// return val;
// }
// return initialValue
// }
两段代码的比较