Driver256 Newbie
Joined: 21 Oct 2005 Posts: 8
|
Posted: 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. |
|