I make a game. I have life,money and damage. When life,money or damage are bigger than 1,000,000,000 i want to show 1B but if i buy something and money are<1B to show again for example 678,234,235.
Asked
Active
Viewed 87 times
-2
-
1Cool game, what language? Also be careful because 32-bit numbers are only capable of showing up to 2b or 4b depending on signed/unsigned. – Uxonith Jan 22 '14 at 16:36
-
i write in actionscript 3 – Alex Jan 22 '14 at 16:36
2 Answers
1
Assuming myNumber
is your number in question, I would do something like this:
var myNumber = 2000000000;
var result;
if (myNumber >= 1000000000)
result = myNumber / 1000000000 + "B";
else
result = myNumber;

Uxonith
- 1,602
- 1
- 13
- 16
-
My game is something like this: http://www.kongregate.com/games/Crovie/idle-mine when i go back and number is lower than 1b to show again the big number – Alex Jan 22 '14 at 16:47
-
@user3224375 then place this inside the main loop (or into a dislpaying routine that's called from within the main loop) – John Dvorak Jan 22 '14 at 16:50
-
So only use `result` for displaying, while keeping `myNumber` as the actual value of your... value. – Uxonith Jan 22 '14 at 16:54
-
works good...but when myNumber is bigger than 2,147,483,647(this is max int value) what i need to do? – Alex Jan 22 '14 at 17:06
-
-
Check [this link](http://stackoverflow.com/questions/1236094/what-is-the-maximum-integer-value-in-flex) – Uxonith Jan 22 '14 at 17:12
0
Why don't you just check it with an if statement? You'll have to pay special attention to what data type you are using since you are dealing with big numbers.
You can also try bit shifting the number and then doing the if statement. It's basically dividing the number to make it smaller and then doing the logical check.

Frank Sposaro
- 8,511
- 4
- 43
- 64
-
Why would a large number comparison need to be preceded by bit shifting? I don't know AS3, but bit shifting coerces the number to 32 bits before shifting, which is exactly the opposite of what we want. – John Dvorak Jan 22 '14 at 16:42
-
I had no frame of reference about this question so I was just trying to suggest different options for him. And one of those options was to avoid a large number comparison in favor of a small number comparison by shifting it. – Frank Sposaro Jan 22 '14 at 16:52
-
If you feel an answer is not answerable because it's missing crucial details (such as the target language), feel free to vote to close instead of trying to answer nevertheless. But a language tag has already been given. Also, I'm not aware of _any_ language where downscaling before comparison might be useful. – John Dvorak Jan 22 '14 at 17:08