Advertisement
SpykeRel04D

this.pn

Sep 14th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. this.pn = function (n,unit,isInt) {
  2. if (unit=="ms") return timer(Math.floor(n/1000));
  3. if (n==0) return "0"+(unit?" "+unit:"");
  4. if (isInt) n=Math.floor(n);
  5. if (data.nMode==0) {
  6. var exp = Math.log10(n);
  7. var mexp = Math.floor(exp/3)*3;
  8. var str = (mexp==0?n:n/Math.pow(10,mexp)).toString();
  9. var parts = str.split(".");
  10. var left = parts[0];
  11. var right = (parts.length>1?parts[1].substr(0,Math.min(2,4-left.length)):"");
  12. //while (right.length>0 && right[right.length-1]=="0") right=right.substr(0,right.length-1);
  13. if (mexp==0 && isInt!==undefined) return left+(unit?" "+unit:"");
  14. else if (mexp==0) return left+(right.length>0?"."+right:"")+" "+UNITS[mexp]+(unit?unit:"");
  15. else if (UNITS[mexp]!==undefined) return left+(right.length>0?"."+right:"")+" "+UNITS[mexp]+(unit?unit:"");
  16. else return "0"+(unit?" "+unit:"");
  17. } else if (data.nMode==1) {
  18. var exp = Math.floor(Math.log10(n));
  19. var mantissa = n/Math.pow(10,exp);
  20. if (exp>=0 && exp<=2 && isInt!==undefined) return n+(unit?" "+unit:"");
  21. else if (exp>=0 && exp<=2) return n.toFixed(2)+(unit?" "+unit:"");
  22. else if (mantissa!=0) return mantissa.toFixed(2)+"e"+exp+(unit?" "+unit:"");
  23. else return "0"+(unit?" "+unit:"");
  24. }
  25. }
  26.  
  27. this.pn(data.energy,"J")
  28.  
  29. this.pn(this.getOmegas()>0?this.getOmegas():0,"\u03A9",true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement