Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display integers with 2 decimal points.

Status
Not open for further replies.

xstar9x

Programmer
Mar 25, 2002
6
CA
When I convert a sting (ex. 1,250.00) to and integer using CInt I get this (ex. 1250) Does anybody know how I can force 2 decimals on it? and possibly a comma as well?
 
The CInt is used to get the integer portion of a number. Use CDbl

Code:
Dim sNumber: sNumber = "1025" '"1025.50"/".25"/"38903872.37"/"38903872.37"
Dim dblNumber: dblNumber = CDbl(sNumber)
MsgBox(dblNumber)
Dim sCurrency: sCurrency = FormatNumber(dblNumber,2,False,False,True)
'FormatNumber(number,numdigits after decimal,include leading digit,use parentheses for negatives,group digits)
MsgBox("$" & sCurrency)

Hope it helps, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
looks good, but there's got to be a more logical way!
 
Wishfull thinking I guess. In VB 5.0 all you have to do is:

Dim money as single
money = 3000
money = Format(money, "Currency")
 
According to Microsoft's VBScript help files, this would be similar to what you're looking for:

FormatCurrency(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit [,UseParensForNegativeNumbers [,GroupDigits]]]])

The FormatCurrency function syntax has these parts:

Part Description

Expression Required. Expression to be formatted.

NumDigitsAfterDecimal Optional. Numeric value indicating how many places to the
right of the decimal are displayed. Default value is -1, which
indicates that the computer's regional settings are used.

IncludeLeadingDigit Optional. Tristate constant that indicates whether or not a
leading zero is displayed for fractional values. See Settings
section for values.

UseParensForNegativeNumbers Optional. Tristate constant that indicates whether or
not to place negative values within parentheses. See
Settings section for values.

GroupDigits Optional. Tristate constant that indicates whether or not
numbers are grouped using the group delimiter specified in
the computer's regional settings. See Settings section for
values.
 
Does the Cdbl function work in VBScript? Sandy
 
Yes, CDbl is a valid VBSCript function. It sometimes does strange things with printing decimals, though, because of the format for storing double precision numbers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top