Currency system similar to "Clicker Heroes" in C#

Hey there!

I’ve been working on an idle clicker game for little under a week now and I’ve seen to hit a stump in development. A lot of the core features of the game are done (Upgrades, points over time, sounds etc…) But, this is just bugging me.

The game needs to be able to handle large numbers, you know, the numbers that put Unity into the negatives, and I have an idea on how I want to do this, it’s just the execution, I can’t do it!

So, I need to be able to make numbers (once they reach like 10,000 etc…) To be formatted like “10k” Instead of “10000” and then from there make it so that instead of “10000k” I could have “10m” I’m not sure how to approach this and I was wondering if you guys could help?

I’m not asking specifically for a script either, that wouldn’t work, I was just wondering if you could tell me how you’d approach it, and how else it could be done efficiently.

P.S. Here is the URL to ClickerHeroes, so that you understand the system I am hoping for…

OK you just hold the number in a variable(e.g. myNumber), then when you want to display it just test the size off the number so

if(myNumber > 999 && myNumber < 1000000)
    tempFloat = myNumber / 1000;
    numToDisplay = (int)tempFloat;
    TextToDisplay = "k";

if lower than 1000 the set numToDisplay = myNumber and TextToDisplay = “”

if larger than 999999 then divide by 1000000 and set your text to “m”

You may need to look up rounding so it always rounds down but it should work along those lines.

Well, I Don’t know if there may be a formatting numbers this way via string.Format() (that would be the best way but I didn’t find it with a quick view) the naive way of doing it is writting a function that does the job. Something like this should do it. Can’t test it right now.

	private string formatNumber(int number) {
		// more than a million add a "m"
		if(number > 999999) {
			return (number / 1000000).ToString() + "m";
		// more than a thousand - add a "k"
		else if(number > 999) {
			return (number / 1000).ToString() + "k";
		// else to nothing
		return number.ToString();