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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Decimal Numbers

Status
Not open for further replies.

zdas04

Technical User
Sep 9, 2003
29
0
0
US
Why are simple things so hard and difficult things so easy?

I'm simply trying to display a number like 16.043 on a msgbox. What I get is 16

When I try to format it with Format(numField,"#0.000", yes, I am an old COBOL programmer) I get 16.000 .

What dumb little thing am I doing wrong?

Thanks

David
 
What is the datatype of the variable that is holding your 16.043 value?

If your value is stored in a double, you can do it like this:
Code:
Dim MyDbl As System.Double
Dim MyFormattedString As String

MyDbl = 16.034
MyFormattedString = MyDbl.ToString("#0.000")

Console.WriteLine(MyFormattedString)

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
ChipH,
Thanks, I like the .ToString option, it seems more consistent with VB than the old CStr(format( syntax I was using. The problem I had turns out to have been that I declared my variable as "Long" when I meant to use "Double" - I hate it when the computer does just what you tell it to do.

David
 
There's also a decimal data type that you can use, which should let you specify the decimal spots.

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top