common.js 751 B

12345678910111213141516171819202122232425
  1. //三位一逗,保留两位小数
  2. export function stateFormat(num,digit = 2) {
  3. if (num) {
  4. if (!isNaN(num) && typeof num === 'number') {
  5. return num.toFixed(digit).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
  6. } else {
  7. return parseFloat(num).toFixed(digit).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
  8. }
  9. } else {
  10. return '0.00'
  11. }
  12. }
  13. //三位一逗,保留两位小数
  14. export function stateFormatLow(num,digit = 2) {
  15. if (num) {
  16. if (!isNaN(num) && typeof num === 'number') {
  17. return Math.floor(num).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
  18. } else {
  19. return Math.floor(parseFloat(num)).toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
  20. }
  21. } else {
  22. return '0.00'
  23. }
  24. }