ManageGolden.js 922 B

1234567891011121314151617181920212223242526272829
  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. },
  11. InitManageGlodenUI(){
  12. this.GoldenLabel.getComponent(cc.Label).string =this.FormatMoney(GlobalD.GameData.GetGolden().toString());
  13. this.Diamondlabel.getComponent(cc.Label).string =this.FormatMoney(GlobalD.GameData.GetDiamond().toString());
  14. },
  15. FormatMoney(s, n) {
  16. n = n > 0 && n <= 20 ? n : 2;
  17. s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
  18. var l = s.split(".")[0].split("").reverse(),
  19. r = s.split(".")[1];
  20. let t = "";
  21. for (let i = 0; i < l.length; i++) {
  22. t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
  23. }
  24. return t.split("").reverse().join(""); //+ "." + r;
  25. }
  26. });