cookie clicker but bigger
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 lines
1.8 KiB

  1. function render(val, places = 3, smallPlaces = 0) {
  2. return numberMode.render(val, places, smallPlaces);
  3. }
  4. function numberTextSmall(val, places = 1, smallPlaces = 0) {
  5. if (isNaN(val)) {
  6. throw new RangeError("Invalid number: " + val);
  7. }
  8. if (val < Math.pow(10, (places+3))) {
  9. return round(val, smallPlaces);
  10. }
  11. let power = Math.floor(Math.log10(val));
  12. let order = Math.floor(power / 3);
  13. adjusted = round(val / Math.pow(1000, order), places).toFixed(places);
  14. if (order <= 8)
  15. return adjusted + " " + _numberWords[order - 1];
  16. else
  17. return numberTextSmall(val / Math.pow(10, 24), places, smallPlaces) + " septillion"
  18. }
  19. function numberText(val, places = 1, smallPlaces = 0) {
  20. if (isNaN(val)) {
  21. throw new RangeError("Invalid number: " + val);
  22. }
  23. if (val < Math.pow(10, (places+3))) {
  24. return round(val, smallPlaces);
  25. }
  26. let power = Math.floor(Math.log10(val));
  27. let order = Math.floor(power / 3);
  28. adjusted = round(val / Math.pow(1000, order), places).toFixed(places);
  29. if (order <= 21)
  30. return adjusted + " " + _numberWords[order - 1];
  31. else
  32. return numberText(val / Math.pow(10, 63), places, smallPlaces) + " vigintillion"
  33. }
  34. _numberWords = {
  35. 0: "thousand",
  36. 1: "million",
  37. 2: "billion",
  38. 3: "trillion",
  39. 4: "quadrillion",
  40. 5: "quintillion",
  41. 6: "sextillion",
  42. 7: "septillion",
  43. 8: "octillion",
  44. 9: "nonillion",
  45. 10: "decillion",
  46. 11: "undecillion",
  47. 12: "duodecillion",
  48. 13: "tredecillion",
  49. 14: "quattuordecillion",
  50. 15: "quindecillion",
  51. 16: "sexdecillion",
  52. 17: "septendecillion",
  53. 18: "octodecillion",
  54. 19: "novemdecillion",
  55. 20: "vigintillion",
  56. }
  57. function numberScientific(val, places = 1, smallPlaces) {
  58. return val.toExponential(places)
  59. }
  60. function numberFull(val, places = 1, smallPlaces) {
  61. return round(val, places);
  62. }