add number formating

This commit is contained in:
biglyderv 2025-03-10 05:31:47 -04:00
parent 3f0b0b8ccc
commit a31a41bb94
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
4 changed files with 27 additions and 2 deletions

View file

@ -46,6 +46,7 @@
</script>
<script src="/js/num.js"></script>
<script src="/js/cube.js"></script>
<script src="/js/mat.js"></script>
<script src="/js/twgl.min.js"></script>

View file

@ -113,7 +113,7 @@ function renderThing() {
gl.uniformMatrix4fv(matBuffer, false, new Float32Array(MDN.perspectiveMatrix(Math.PI * 100 / 180, ratio, 0.01, 1000)));
hud.textContent = `${Math.floor(nothingness * 100) / 100} nil; ${Math.floor((nGain + getBonus) * 60 * 100) / 100} nil/sec`
hud.textContent = `${numify(nothingness)} nil; ${numify((nGain + getBonus) * 60)} nil/sec`
gl.uniform1f(sizeBuffer, -Math.log(nothingness));

24
docs/js/num.js Normal file
View file

@ -0,0 +1,24 @@
let illions = [
"", "k", "M", "B", "T", "qd", "Qn", "sx", "Sp", "O", "N", "de", "Ud", "DD", "tdD", "qdD", "QnD", "sxD", "SpD", "OcD", "NvD", "Vgn", "UVg", "DVg", "TVg", "qtV", "QnV", "SeV", "SPG", "OVG", "NVG", "TGN", "UTG", "DTG", "tsTG", "qtTG", "QnTG", "ssTG", "SpTG", "OcTG", "NoTG", "QdDR", "uQDR", "dQDR", "tQDR", "qdQDR", "QnQDR", "sxQDR", "SpQDR", "OQDDr", "NQDDr", "qQGNT", "uQGNT", "dQGNT", "tQGNT", "qdQGNT", "QnQGNT", "sxQGNT", "SpQGNT", "OQQGNT", "NQQGNT", "SXGNTL"
];
function numify(x) {
x = x * 1;
let il = Math.log(x) / Math.log(1000);
il = Math.floor(il);
let base = x / (1000 ** il);
base = base.toString();
base = base.slice(0,Math.min(base.length,5))
if (il in illions && !isNaN(x) && Math.abs(x) != Infinity) {
return `${base}${illions[il]}`
} else if (x == 0 || isNaN(x) || Math.abs(x) == Infinity) {
return `${x}`;
} else if (x < 0) {
return `-${numify(x)}`
} else if (x < 1) {
return `1/${numify(1 / x)}`
} else if (il > illions.length - 1) {
return `10^${numify(Math.log10(x))}`
}
}

View file

@ -37,7 +37,7 @@ upgrades = [
let hud2 = document.querySelector('.hud');
function updateText(button, price, name, cc) {
button.textContent = `Buy ${name} (${cc}x) for ${price} nil`
button.textContent = `Buy ${name} (${cc}x) for ${numify(price)} nil`
}
for (let upgrade of upgrades) {