Jump to content


Photo

***SOLVED*** Number format help needed?


  • Please log in to reply
3 replies to this topic

#1 Arc

Arc

    GMC Member

  • GMC Member
  • 208 posts
  • Version:GM8

Posted 13 April 2011 - 05:02 AM

I use GM8 Pro

Hello, I use the following code to generate a whole number between, and including, 0 to 500000. I store this random number in a variable named, tempNum. My question is this, how can I format the number that is stored in tempNum to have commas so it is easier to read? example: from 123729 to 123,729 Please help? Thanks!

tempNum = irandom_range(0,500000);


Thanks!

Edited by Arc, 13 April 2011 - 07:56 AM.

  • 0

#2 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 13 April 2011 - 07:16 AM

Just whipped up this code.

var temp, i;
temp = string(argument0);
for (i=0; i< string_length(temp) div 4; i+=1)
{
  temp = string_insert(",",temp,string_length(temp)-4*i-2);
}    
return temp;

Put it in a script called, say, format_commas. Then to use it, draw_string(x,y,format_commas(tempNum));

Edited by Dangerous_Dave, 13 April 2011 - 08:00 AM.

  • 0

#3 Arc

Arc

    GMC Member

  • GMC Member
  • 208 posts
  • Version:GM8

Posted 13 April 2011 - 07:56 AM

Thanks, works perfectly!
  • 0

#4 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 13 April 2011 - 08:00 AM

No problem, happy to help :D
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users