1234567891011121314151617181920212223242526 |
- //三位一逗,保留两位小数
- 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'
- }
- }
- //三位一逗,保留两位小数
- export function stateFormatLow(num,digit = 2) {
-
- if (num) {
- if (!isNaN(num) && typeof num === 'number') {
- return Math.round(num).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
- } else {
- return Math.round(parseFloat(num)).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
- }
- } else {
- return '0'
- }
- }
|