You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

13 lines
377 B

export default function groupSeparator(value, groupSeparator = ',') {
if (!value) {
return value;
}
const val = String(value);
const cells = val.match(/^(-?)(\d*)(\.(\d+))?$/);
if (!cells) {
return value;
}
let int = cells[2] || '0';
let n = cells[3] || '';
return int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator) + n;
}