ManageGolden.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. GoldenLabel: cc.Node,
  5. Diamondlabel: {
  6. default: null,
  7. type: cc.Node,
  8. },
  9. ManageUI: cc.Node,
  10. //5个神农呗兑1个cnt
  11. CNTNode: {
  12. default: null,
  13. type: cc.Node,
  14. },
  15. SNBNode: {
  16. default: null,
  17. type: cc.Node,
  18. },
  19. },
  20. InitManageGlodenUI() {
  21. this.GoldenLabel.getComponent(cc.Label).string = this.formatPrice(
  22. GlobalD.GameData.GetGolden().toString()
  23. )
  24. this.Diamondlabel.getComponent(cc.Label).string = this.formatPrice(
  25. GlobalD.GameData.GetDiamond().toString()
  26. )
  27. this.CNTNode.getComponent(cc.Label).string = this.formatPrice(
  28. GlobalD.GameData.GetCNT().toString()
  29. )
  30. // console.log(" GlobalD.GameData.GetSNB() = ", GlobalD.GameData.GetSNB());
  31. this.SNBNode.getComponent(cc.Label).string = this.formatPrice(
  32. GlobalD.GameData.GetSNB().toString()
  33. )
  34. },
  35. formatPrice(price) {
  36. return String(price).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  37. },
  38. FormatMoney(s, n) {
  39. n = n > 0 && n <= 20 ? n : 2
  40. s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + ''
  41. var l = s.split('.')[0].split('').reverse(),
  42. r = s.split('.')[1]
  43. let t = ''
  44. for (let i = 0; i < l.length; i++) {
  45. t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? ',' : '')
  46. }
  47. return t.split('').reverse().join('') //+ "." + r;
  48. },
  49. })