Hi everyone, in this blog post we will go over an example c3 file i adapted from a stackoverflow into C3 for a forum user asking for a Large Formating number to be used in a game.
What this tutorial will help you achieve:
Any large number up to SxTillions converted to a short number with control over decimals and a suffix.
An example to understand here is as following
You have a tycoon game or idle game that has a no-limit infinity upgrade mode to it, think cookie cliker, business tycoon etc
So your user will have after a while sums of in-game cash like 1,000,000,000,000,000,000 which means he ammased 1 Quintillion in-game funds... and turn it into 1.0Qt if is a perfect round number and 1Qt or 1.15Qt or 1.156Qt etc all this is customizable inside the example file and u have control how many digits you can display.
Displaying this large number in any game can be comborsome, and we all know even with the largest displays it looks just weird having a long sausage text showing you 000000 or a string of numbers occupying space.
Space that you can use to focus on more details or cramming the HUD info or menu buttons inside off.
So lets begin?
What we need
3 global variables (numbers)
1-Money = total ammount player has
2-Divider = divide the total ammount of money by 10^N
3-Decimal = where to place the decimal and show text with more control.
1 global string (text)
-Suffix - displays the Text we want after the number ie. 1,000,000 or 1Million becomes 1.0M
1-Text object to display our Money - lets call it DisplayText and have default value text as "Money:"
1-Touch Plugin - you can use mouse or anything i like to use the Touch plugin because i find the "on tap" to have more control over how things are being triggered once and force users to avoid spamming "gains" by simply keeping pressed.
Event Sheet structure
1)-> touch.OnTapGesture (or Any Trigger) = Action> CallFunction Trigger_Format_Suffix
2) On Function "Trigger_Format_Suffix" = Action > Set Money to Money + (10^6)*1.125
- abs(Money) >= 10^21 Set Suffix to "Sx", Set Divisor to 10^21
3 Else if abs(InputNumber) >= 1.0e+9 Set Suffix to "B", Set Divisor to 1.0e+9
4 Else if abs(InputNumber) >= 1.0e+6 Set Suffix to "M", Set Divisor to 1.0e+6
5 Else if abs(InputNumber) >= 1.0e+3 Set Suffix to "k", Set Divisor to 1.0e+3
6 Else Set Suffix to "", Set Divisor to 1.0
7 (After setting Divisor) Check if there's a remainder using floor function:
8 If floor(InputNumber / Divisor) = InputNumber / Divisor Set ConvertedText to floor(InputNumber / Divisor) & Suffix
9 Else Set ConvertedText to round(InputNumber / Divisor * 100) / 100 & Suffix