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!!