ManageGolden.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.FormatMoney(GlobalD.GameData.GetGolden().toString());
  22. this.Diamondlabel.getComponent(cc.Label).string = this.FormatMoney(GlobalD.GameData.GetDiamond().toString());
  23. this.CNTNode.getComponent(cc.Label).string = this.FormatMoney(GlobalD.GameData.GetCNT().toString());
  24. this.SNBNode.getComponent(cc.Label).string = this.FormatMoney(GlobalD.GameData.GetSNB().toString());
  25. },
  26. FormatMoney(s, n) {
  27. n = n > 0 && n <= 20 ? n : 2;
  28. s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
  29. var l = s.split(".")[0].split("").reverse(),
  30. r = s.split(".")[1];
  31. let t = "";
  32. for (let i = 0; i < l.length; i++) {
  33. t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
  34. }
  35. return t.split("").reverse().join(""); //+ "." + r;
  36. }
  37. });