Format(price, "#.0")

F

fniles

Say price = 4179.00 or 4179
In VB6, when I do Format(price, "#.0"), it returns 4179.0, but in VB.NET
when I do String.Format(price, "#.0"), it returns 4179.00.
How can I do Format(price, "#.0") in VB.NET ?
Thank you.
 
H

Herfried K. Wagner [MVP]

fniles said:
Say price = 4179.00 or 4179
In VB6, when I do Format(price, "#.0"), it returns 4179.0, but in VB.NET
when I do String.Format(price, "#.0"), it returns 4179.00.
How can I do Format(price, "#.0") in VB.NET ?

\\\
MsgBox(Format(price, "#.0"))
///

In this particular case it's the same as in VB6.
 
A

Armin Zingler

fniles said:
Say price = 4179.00 or 4179
In VB6, when I do Format(price, "#.0"), it returns 4179.0, but in
VB.NET when I do String.Format(price, "#.0"), it returns 4179.00.
How can I do Format(price, "#.0") in VB.NET ?
Thank you.

Really
String.Format(price, "#.0")
?

This can not even be compiled. Enable Option Strcit to see these faults
ASAP. Press F1 to get the argument description: The first one must be the
format. The valid formats are described in the help,
too. ..... This one:
http://msdn2.microsoft.com/en-us/library/427bttx3.aspx


Armin
 
M

Mythran

fniles said:
Say price = 4179.00 or 4179
In VB6, when I do Format(price, "#.0"), it returns 4179.0, but in VB.NET
when I do String.Format(price, "#.0"), it returns 4179.00.
How can I do Format(price, "#.0") in VB.NET ?
Thank you.

You would use String.Format("{0:#.0}", price).

HTH,
Mythran
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

fniles said:
Say price = 4179.00 or 4179
In VB6, when I do Format(price, "#.0"), it returns 4179.0, but in VB.NET
when I do String.Format(price, "#.0"), it returns 4179.00.
How can I do Format(price, "#.0") in VB.NET ?
Thank you.

The format is the first parameter, so you would be using the string
representation if the price as format, and as it doesn't contain any
formatting at all, the second parameter wouldn't be used at all.

Use String.Format("{0:#.0}", price) or price.ToString("#.0").
 

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

Similar Threads

Sliding scale for Mark Up 0
Boiler Cover Recommendations 6
Format$ question 7
simple String formatting question 2
Index on DataTable ? 3
Databinding 1
IFormattable interface 3
Sum [Price] IIF [BelowSetFloor] >0 1

Top