decimal spaces between large numbers (hundred millions)

camerakid

Member
Hey Everyone,

I bumped into an interesting logical problem. In some countries the decimal marking is different.

US: 1,000,000.10
Europe: 1 000 000,10
Spain: 1.000.000,10

So I was wondering what do you think is the best solution would be for showing large numbers in a game?

In my view the European is more logical by leaving spaces, so it is much easier to read out 100 million for everyone in the world:

100000000
100 000 000

Actually how would I draw spaces into my variable after converting it to a string, any ideas?

EDIT:

I came up with this solution can anyone suggest a more simpler one?

<code>

number=string(global.money);

if global.money>=0
{
number2=number;
}

if global.money>=1000
{
number2=string_insert(" ",number,2);
}

if global.money>=10000
{
number2=string_insert(" ",number,3);
}

if global.money>=100000
{
number2=string_insert(" ",number,4);
}

if global.money>=1000000
{
number1=string_insert(" ",number,2);
number2=string_insert(" ",number1,6);
}

if global.money>=10000000
{
number1=string_insert(" ",number,3);
number2=string_insert(" ",number1,7);
}

if global.money>=100000000
{
number1=string_insert(" ",number,4);
number2=string_insert(" ",number1,8);
}

text="$"+number2;

draw_text(x,y,text);

<code>

Thanks.

Attila
 
Last edited:

wamingo

Member
just whipped this up.. damn you Aura! wait, no, mine is better. Much more better!
Code:
///sCommafy2(num, decimals, substr)
// allows negative numbers
var decimals=argument1;
var str=string_format(argument0,0,decimals);
var substr=argument2, p=0;
if(decimals==0) p=string_length(str)-2;
else p = string_pos('.',str)-3;
for(var i=p; i>1+(argument0<0); i-=3)
  str = string_insert(substr, str,i);
return str;
Code:
sCommafy2( 1200300.12345, 3, ' ')    // returns "1 200 300.123"
edit: fixed 0 decimals and negative numbers.
 
Last edited:
D

Dennis Ross Tudor Jr

Guest
adding spaces to a string could involve string_insert(substr, str, index); where you used some type of iteration(repeat, for,while, do, etc..) from right to left, or from end to start, or string_legth(text)-2 to zero, and insert a space every 3 characters. we start with (-2) because the space inserted in the first past will make it (3) long at the ned
Code:
text="100000000000";
for(pos = string_length(text)-2; pos>=0; pos-=3){
    text=string_insert(" ",text, pos);  //should do the trick.
}
EDIT: some people just type faster :p
 
Top