The Format Number function integrates functionality of the round
function. For instance
dim x : x = 1.45776343
dim y : y = FormatNumber(x, 2)
speak y
will speak 1.46
On 12/19/2009 12:02 PM, Chip Orange wrote:
thanks Jared; this is quite helpful.
One thing it didn't mention though, and what I would have responded to
David's question with, is the Round() function.
this takes 2 parameters: the number, and how many decimal places you
want it rounded to. so, if x holds 3.141592 then round(x,2) gives you
3.14
it looked like format truncated.
Chip
------------------------------------------------------------------------
*From:* Jared Wright [mailto:[email protected]]
*Sent:* Saturday, December 19, 2009 8:14 AM
*To:* [email protected]
*Subject:* Re: VBScript, displaying decimals
David, You might find this article on working with numbers in VBScript
helpful.
http://technet.microsoft.com/en-us/library/ee176975.aspx
I have pasted a relevant section about the format number function below.
Another helpful function having to do with numbers is FormatNumber
. This function allows you to, well, format a number. FormatNumber can
take as many
as five parameters:
Number: The number you want to format.
NumberOfDigits: The number of digits you want displayed after the
decimal point. For example, if
you pass the number 1.5 but specify 2 as the number of digits,
FormatNumber will
return 1.50.
LeadingZeroes: This can be one of three values. -1
indicates that you want to display a leading zero when you're working
with fractions.
For example, .75 would be displayed as 0.75. A
0 indicates that you don't want to display a leading zero. -2
indicates that you want to use the regional settings on the computer
to determine
whether leading zeroes are displayed.
NegativesInParens: This can be one of three values. If you pass a
value of -1
negative numbers will be displayed in parentheses rather than with a
minus sign.
For example, if you pass the number -5 your output will be (5). A value of
0 indicates you don't want to use parentheses to represent negative
numbers, and a
value of -2 indicates that the regional settings should be used.
GroupDigits: This parameter can also be one of three values. A -1
indicates that you want to use the delimiter listed in the regional
settings to
group thousands. For example, if you pass the number 5000 and your
system settings
use a comma as a delimiter, your output will be 5,000. A
0 indicates you don't want to do any grouping, and -2 also means use
the regional
settings.
All parameters but the first are optional. If you don't specify any of
the others,
the regional settings for the computer will be used.
The link also icnludes an example if you wish to see that.
Best,
Jared
On 12/19/2009 5:41 AM, David wrote:
In VBS, the line:
Average = Seconds / Activities
returns a number like
73.12985763432
How can I get it to show up as 73.13, or maybe 73.1298? In other
words, is there a function that lets me decide how many decimals I
want displayed?
Thanks,