PDA

View Full Version : Solved: Display Decimal Values



Kindly_Kaela
03-14-2007, 07:19 AM
Hello everyone.

Please advise on how to change the following macro so that it will display decimal digits.

The following code results in $34.00 (instead of the desired $33.75). I don't want it to round up. Instead, I want the decimal digits to display.



Sub DecimalText()

Dim Num As Long
Dim NumText As String

Num = 33.75

NumText = CStr(Format(Num, "$#,##0.00;($#,##0.00)"))

MsgBox (NumText)

End Sub

lucas
03-14-2007, 08:33 AM
Dim num as string...
Sub DecimalText()

Dim Num As String
Dim NumText As String

Num = 33.75

NumText = CStr(Format(Num, "$#,##0.00;($#,##0.00)"))

MsgBox (NumText)

End Sub

Tommy
03-14-2007, 08:45 AM
Hi Kindly_Kaela,

Dim the var as double or single you have dimed the variable as a long which will round the 33.75

Sub DecimalText()

Dim Num As Double
Dim NumText As String

Num = 33.75

NumText = Format(Num, "$#,##0.00")

MsgBox (NumText)

End Sub

lucas
03-14-2007, 08:47 AM
Hey Tommy,
good to see you on the board...hope all is well with you and yours.

Kindly_Kaela
03-14-2007, 09:12 AM
Thank you guys! One more question.... I was using the CSTr command to declare a 'string' so I wouldn't have to use a Dim statment. If I was to use Double instead...what would replace CSTr?




Selection.TypeText Text:=CStr(Format(R2, "$#,##0.00;($#,##0.00)"))

Kindly_Kaela
03-14-2007, 09:16 AM
I found my own answer...but now I've lost the $. Any suggestions?



Sub DecimalText()

Num = 33.75

NumText = CDbl(Format(Num, "$#,##0.00;($#,##0.00)"))

MsgBox (NumText)

End Sub

Kindly_Kaela
03-14-2007, 09:18 AM
Got it :)


Sub DecimalText()

NumText = CStr(Format(CDbl(33.75), "$#,##0.00;($#,##0.00)"))

MsgBox (NumText)

End Sub

mdmackillop
03-14-2007, 12:53 PM
How about
Sub DecimalText()
Dim Num As Single
Num = 33.75
MsgBox Format(Num, "$#,##0.00")
End Sub

Tommy
03-14-2007, 04:12 PM
Hey Steve :hi:

All's good :0) doesn't do any good to complain I just like to :rofl:

Kindly_Kaela, I was in a meeting all day demoing a program release, I normally respond sooner. I would use what mdmackillop posted. It's alot more readable. :)