Blogger Information
Blog 26
fans 0
comment 0
visits 21626
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
将金额千分位转化成数字 插件
default
Original
672 people have browsed it
  1. var fmt = {
  2. /**
  3. * 将金额千分位转化成数字
  4. * eg:num = 1,000 --- 1000
  5. */
  6. delectCommafy: function (num) {
  7. return num.replace(/,/g, '') * 1;
  8. },
  9. formatCurrency: function (value) {
  10. return "¥ " + fmt.formatNumber(value, 0);
  11. },
  12. formatCoin: function (value,precision = 0) {
  13. return fmt.formatNumber(value, precision);
  14. },
  15. abs: function (value) {
  16. return Math.abs(value);
  17. },
  18. percent: function (a, b) {
  19. var str = parseInt(a / b * 100);
  20. str += "%";
  21. return str
  22. },
  23. int: function (value) {
  24. return parseInt(value);
  25. },
  26. formatNumber: function (value, precision = 2) {
  27. value = Math.abs(value);
  28. //整数部分
  29. var intv = Math.floor(value);
  30. var arr = [];
  31. if (intv < 0.01) {
  32. arr.push("0");
  33. } else {
  34. while (intv > 0) {
  35. if (intv >= 1000) {
  36. arr.push(fmt.intToString(intv % 1000, 3));
  37. } else {
  38. arr.push(intv);
  39. }
  40. intv = Math.floor(intv / 1000);
  41. }
  42. }
  43. arr.reverse();
  44. var part1 = arr.join(',');
  45. if (precision == 0) {
  46. return part1;
  47. }
  48. var value2 = value;
  49. var part2 = "";
  50. for (var i = 0; i < precision; i++) {
  51. part2 = part2 + Math.floor(value2 * 10 % 10);
  52. value2 = value2 * 10;
  53. }
  54. return part1 + "." + part2;
  55. },
  56. intToString: function (value, length) {
  57. var result = "";
  58. while (value > 0) {
  59. result = (value % 10) + result;
  60. value = Math.floor(value / 10);
  61. }
  62. var rest = length - result.length;
  63. for (var i = 0; i < rest; i++) {
  64. result = "0" + result;
  65. }
  66. return result;
  67. }
  68. };
  69. export default fmt;
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post