【发布时间】:2016-01-15 05:09:38
【问题描述】:
我正在创建一个空闲游戏(Cookie Clicker 等),似乎当我的玩家达到高点击量时,游戏开始变慢。 高数字也不适合游戏,因为它占用了太多空间。那么是否有一个脚本可以将每个数字转换为prefix?
例子:
10 = 10
10000000 变成 100 万。
1,000,000,000 变成 10 亿
1,000,000,000,000 变成 1 万亿
1.4 万亿就是 1400000000000000
它与this 非常相似。
Cookie Clicker 和 swarm 模拟器具有我正在寻找的功能。
编辑:谢谢,Drew Quick!
对于那些感兴趣的人:
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>
希望对你有帮助!!
【问题讨论】:
-
这些可怜的人要点击多少次?
-
有一些自动点击升级。我会说高达一万亿左右。
-
1,000,000,000 becomes 1 billion.... 1,000,000,001 会变成什么? -
我数学不好,可以是 1.000000001,也可以是科学计数法。但我更喜欢它是短期的。 (onlineconversion.com/large_numbers.htm) 也可以四舍五入。
标签: javascript numbers