0

I'm creating an idle game(Cookie Clicker etc.), it seems that when my players reach a high amount of clicks, the game starts to slow down. High numbers doesn't fit well in the game either since it takes up too much space. So is there a script that converts every number to a prefix?

Example:

10 = 10

10000000 becomes 1 million.

1,000,000,000 becomes 1 billion

1,000,000,000,000 becomes 1 trillion

1.4 quadrillion would be 1400000000000000
It's quite similar to this.

Cookie Clicker and swarm simulator has the feature that I'm looking for.

Edit: Thanks, Drew Quick!

For those who's interested:

var count = 1;

function main() {
  count += 1000;
  
var str = count.toString();
var tmpCount = '';
if (count < 1000000) {
    tmpCount = "";
} else if (count > 1000000 && count < 1000000000) {
    str = "Million";
    tmpCount = (count / 1000000).toFixed(2);
} else if (count > 1000000000 && count < 1000000000000) {
    str = "Billion";
    tmpCount = (count / 1000000000).toFixed(2);
} else if (count > 1000000000000 && count < 1000000000000000) {
    str = "Trillion";
    tmpCount = (count / 1000000000000).toFixed(2);
} else if (count > 1000000000000000 && count < 1000000000000000000) {
str = "Quadrillion";
    tmpCount = (count / 1000000000000000).toFixed(2);
}     else if (count > 1000000000000000000 && count < 1000000000000000000000) {
    str = "Quintillion";
    tmpCount = (count / 1000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000 && count < 1000000000000000000000000) {
    str = "Sextillion";
    tmpCount = (count / 1000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000 && count < 1000000000000000000000000000) {
    str = "Septillion";
    tmpCount = (count / 1000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000 && count < 1000000000000000000000000000000) {
    str = "Octillion";
    tmpCount = (count / 1000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000 && count < 1000000000000000000000000000000000) {
    str = "Nonillion";
    tmpCount = (count / 1000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000 && count < 1000000000000000000000000000000000000) {
    str = "Decillion";
    tmpCount = (count / 1000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000 && count < 1000000000000000000000000000000000000000) {
    str = "Undecillion";
    tmpCount = (count / 1000000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000000 && count < 1000000000000000000000000000000000000000000) {
    str = "Duodecillion";
    tmpCount = (count / 1000000000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000000000 && count < 1000000000000000000000000000000000000000000000) {
    str = "Tredecillion";
    tmpCount = (count / 1000000000000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000000000000 && count < 1000000000000000000000000000000000000000000000000) {
    str = "Quattuordecillion";
    tmpCount = (count / 1000000000000000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000000000000000 && count < 1000000000000000000000000000000000000000000000000000) {
    str = "Quindecillion";
    tmpCount = (count / 1000000000000000000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000000000000000000 && count < 1000000000000000000000000000000000000000000000000000000) {
    str = "Sexdecillion";
    tmpCount = (count / 1000000000000000000000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000000000000000000000 && count < 1000000000000000000000000000000000000000000000000000000000) {
    str = "Septendecillion";
    tmpCount = (count / 1000000000000000000000000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000000000000000000000000 && count < 1000000000000000000000000000000000000000000000000000000000000) {
    str = "Octodecillion";
    tmpCount = (count / 1000000000000000000000000000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000000000000000000000000000 && count < 1000000000000000000000000000000000000000000000000000000000000000) {
    str = "Novemdecillion";
    tmpCount = (count / 1000000000000000000000000000000000000000000000000000000000000).toFixed(2);
} else if (count > 1000000000000000000000000000000000000000000000000000000000000000 && count < 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) {
    str = "Vigintillion";
    tmpCount = (count / 1000000000000000000000000000000000000000000000000000000000000000).toFixed(2);
} else if (count > 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 && count) {
    str = "Googol";
    tmpCount = (count / 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000).toFixed(2);
}


  document.getElementById("count").innerText = tmpCount + ' ' + str;
  setTimeout(function() {
    main();
  }, 1);
}

main();
<span id="count">test</span>

Hope it helps!!

Community
  • 1
  • 1
Jason
  • 1
  • 6
  • How many times do these poor people have to click? – Chris Trudeau Jan 15 '16 at 05:12
  • There are some auto-clicking upgrades. I'd say up to a trillion or so. – Jason Jan 15 '16 at 05:15
  • 2
    `1,000,000,000 becomes 1 billion.` ... what does 1,000,000,001 become? – Jaromanda X Jan 15 '16 at 05:17
  • I'm no good at maths though, it can be 1.000000001 or it could be in scientific notation. But i prefer it to be in short terms. (http://www.onlineconversion.com/large_numbers.htm) It can also possibly be rounded off too. – Jason Jan 15 '16 at 05:50

1 Answers1

0

How can I convert numbers into scientific notation?

var clicks = 100000000000000000000000;
alert(clicks.toExponential());

Edit: What about something simple and straight forward like so? This is rough by the way. Just to get the idea across.

var count = 1;

function main() {
  count += 1000;

  var str = count.toString();
  var tmpCount;
  if (count < 1000000) {
    tmpCount = "";
  } else if (count > 1000000 && count < 1000000000) {
    str = "million";
    tmpCount = (count / 1000000).toFixed(2);
  } else if (count > 1000000000 && count < 1000000000000) {
    str = "billion";
    tmpCount = (count / 1000000000).toFixed(2);
  }

  document.getElementById("count").innerText = tmpCount + ' ' + str;
  setTimeout(function() {
    main();
  }, 1);
}

main();
<span id="count">test</span>
Community
  • 1
  • 1
hack3rfx
  • 573
  • 3
  • 16