Format(price, "#.0")

  • Thread starter Thread starter fniles
  • Start date Start date
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.
 
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.
 
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
 
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
 
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").
 
Back
Top