Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » Finished MUD Scripts
Driver256
Newbie


Joined: 21 Oct 2005
Posts: 8

PostPosted: Fri Oct 28, 2005 5:42 pm   

Formatting big numbers in ZMud using VBScript
 
There are many posts in these forums asking about formatting numbers. That is, adding commas to make them display friendly. The consensus seems to be to use %format, which works pretty well for small numbers.

However, I found %format to be a little quirky sometimes, and it won't do long-doubles. Some have posted long aliases to reformat their strings. These involve a nested series of #if statements, or some other conditionals, used to manually insert commas using %insert. This is a slow and tedious method.

So, because I don't really like the %format command, I once again have turned to VBScript for a simple solution:

Code:
#SCRIPT {Function addcommas(number):addcommas = FormatNumber(number,0):End Function}


Now:

Code:
#show %mss(addcommas(12345678901234))

12,345,678,901,234


This works for large numbers, and is much faster to execute than all those nested #ifs.

If you need to preserve decimal places, you can change the paramaters of the FormatNumber function in the VBScript to get what you want. Explore the VBScript documentation for more information: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctexp.asp

Have a nice day,

Berndt

PS. VBScript rocks my world.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » Finished MUD Scripts All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net