Decimal formatting

V

Vik

Dim Dec As Decimal, Str1, Str2 As String

Dec = 1

Str1 = Dec.ToString ' Str1 = "1"

Dec = "1.0000"

Str2 = Dec.ToString("G") ' Str2 = "1.0000"

Is it possible to format Str2 so that Str2 = "1"?

Thanks.
 
V

Vik

Thank you for reply.

Sorry, my question was not quite correct. I wonder if there is one format
code that provides the following:

Dec = 1.1234
Str2 = Dec.ToString(Some format) ' Str2 = "1.1234"
Dec = "1.0000"
Str2 = Dec.ToString(The same format as above) ' Str2 = "1"

Actually a program doesn't assign "1.0000" to Dec. The program reads data
from a decimal column in a SQL Server database.

Viktor
 
X

xhead

Dim dec As Decimal, fmt As String
fmt = "0.####"
dec = 1.242
System.Diagnostics.Debug.WriteLine(dec.ToString(fmt))
dec = 1
System.Diagnostics.Debug.WriteLine(dec.ToString(fmt))
--------
Output window:
1.242
1


Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top