Last active
April 11, 2025 16:46
-
-
Save DamianDominoDavis/bce32c05229b0eadbc43efcd17a77a5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# abbreviate a number as thousands, millions, billions | |
string kmb_num(float x) { | |
if (x<0) | |
return '-'+kmb_num(0-x); | |
for i from 9 to 3 | |
if (x >= 10**i) | |
return (x.to_float()/10**(3*(i/3))).to_string('%'+(i-(i%3))+'.'+(2-i%3)+'f') + string[]{'k','M','B'}[i/3-1]; | |
return (x.to_int().to_float() != x && x.to_int().to_string('%d').length() < 3) | |
? x.to_string('%1.2f') | |
: x.to_int().to_string('%d'); | |
} | |
# express a number in terms of Mr. Accessory | |
# optionally a fractional number of Misters Accessory | |
# else an integer number of A's, plus abbreviated change | |
string mra_num(float x, boolean frac) { | |
static int A = $item[Mr. Accessory].mall_price(); | |
int left = x / A; | |
float right = x - left*A; | |
if (!frac) | |
return (left > 0? left+'A' : '') | |
+ (left > 0 && right >= 1000000? '+' : '') | |
+ (right >= 1000000 ? right.kmb_num() : ''); | |
else { | |
return (x/(A).to_float()).to_string('%.1f') + 'A'; | |
} | |
} | |
string mra_num(float x) { | |
return mra_num(x, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment