12345678910111213141516171819202122232425 |
- //三位一逗,保留两位小数
- export function stateFormat(num,digit = 2) {
- if (num) {
- if (!isNaN(num) && typeof num === 'number') {
- return num.toFixed(digit).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
- } else {
- return parseFloat(num).toFixed(digit).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
- }
- } else {
- return '0.00'
- }
- }
- //三位一逗,保留两位小数
- export function stateFormatLow(num,digit = 2) {
- if (num) {
- if (!isNaN(num) && typeof num === 'number') {
- return Math.floor(num).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
- } else {
- return Math.floor(parseFloat(num)).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
- }
- } else {
- return '0.00'
- }
- }
|