Home All Groups Group Topic Archive Search About

Another String.Format() Question

Author
28 Oct 2006 11:17 PM
thomas
Hello Everyone,

I am trying to format decimal values the way so decimal point is display
only if the number is any digits after decimal other than zero.

Example:
9.000000 -> "9"
9.500000 -> "9.5"

Does anyone have an idea how the format string should look like? Is it, at
all, possible?

Tomasz

Author
29 Oct 2006 12:55 AM
Bryan Phillips
If you can use the double data type, you can just call ToString() and it
will trim off the zeros and decimal point.

Bryan Phillips
MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com



Show quote
"thomas" <tho***@thomas.com> wrote in message
news:#gs8Bdu#GHA.4356@TK2MSFTNGP05.phx.gbl:

> Hello Everyone,
>
> I am trying to format decimal values the way so decimal point is display
> only if the number is any digits after decimal other than zero.
>
> Example:
> 9.000000 -> "9"
> 9.500000 -> "9.5"
>
> Does anyone have an idea how the format string should look like? Is it, at
> all, possible?
>
> Tomasz
Author
29 Oct 2006 3:32 PM
Milosz Skalecki
Bryan,

No need for that. He may use:

decimal x = 19.5M;
string formatedValue = x.ToString(""0.########"");

For more information check MSDN for 'Custom Numeric Format Strings'.
Hope this helps

--
Milosz Skalecki
MCP, MCAD


Show quote
"Bryan Phillips" wrote:

> If you can use the double data type, you can just call ToString() and it
> will trim off the zeros and decimal point.
>
> Bryan Phillips
> MCSD, MCDBA, MCSE
> Blog:  http://bphillips76.spaces.live.com
>
>
>
> "thomas" <tho***@thomas.com> wrote in message
> news:#gs8Bdu#GHA.4356@TK2MSFTNGP05.phx.gbl:
>
> > Hello Everyone,
> >
> > I am trying to format decimal values the way so decimal point is display
> > only if the number is any digits after decimal other than zero.
> >
> > Example:
> > 9.000000 -> "9"
> > 9.500000 -> "9.5"
> >
> > Does anyone have an idea how the format string should look like? Is it, at
> > all, possible?
> >
> > Tomasz
>
>
Author
29 Oct 2006 4:12 PM
Milosz Skalecki
Small bug - double quotes :)

it should be:
decimal x = 19.5M;
string formatedValue = x.ToString("0.########");

Pozdro Tomek :D
--
Milosz Skalecki
MCP, MCAD


Show quote
"Milosz Skalecki" wrote:

> Bryan,
>
> No need for that. He may use:
>
> decimal x = 19.5M;
> string formatedValue = x.ToString(""0.########"");
>
> For more information check MSDN for 'Custom Numeric Format Strings'.
> Hope this helps
>
> --
> Milosz Skalecki
> MCP, MCAD
>
>
> "Bryan Phillips" wrote:
>
> > If you can use the double data type, you can just call ToString() and it
> > will trim off the zeros and decimal point.
> >
> > Bryan Phillips
> > MCSD, MCDBA, MCSE
> > Blog:  http://bphillips76.spaces.live.com
> >
> >
> >
> > "thomas" <tho***@thomas.com> wrote in message
> > news:#gs8Bdu#GHA.4356@TK2MSFTNGP05.phx.gbl:
> >
> > > Hello Everyone,
> > >
> > > I am trying to format decimal values the way so decimal point is display
> > > only if the number is any digits after decimal other than zero.
> > >
> > > Example:
> > > 9.000000 -> "9"
> > > 9.500000 -> "9.5"
> > >
> > > Does anyone have an idea how the format string should look like? Is it, at
> > > all, possible?
> > >
> > > Tomasz
> >
> >
Author
29 Oct 2006 4:12 PM
Bryan Phillips
Good call.  Thanks.

Bryan Phillips
MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com



Show quote
"Milosz Skalecki" <mily***@REMOVEITwp.pl> wrote in message
news:C119E0A7-7931-4453-B231-594CF76CEC60@microsoft.com:

> Bryan,
>
> No need for that. He may use:
>
> decimal x = 19.5M;
> string formatedValue = x.ToString(""0.########"");
>
> For more information check MSDN for 'Custom Numeric Format Strings'.
> Hope this helps
>
> --
> Milosz Skalecki
> MCP, MCAD
>
>
> "Bryan Phillips" wrote:
>
>
> > If you can use the double data type, you can just call ToString() and it
> > will trim off the zeros and decimal point.
> >
> > Bryan Phillips
> > MCSD, MCDBA, MCSE
> > Blog:  http://bphillips76.spaces.live.com
> >
> >
> >
> > "thomas" <tho***@thomas.com> wrote in message
> > news:#gs8Bdu#GHA.4356@TK2MSFTNGP05.phx.gbl:
> >
>
> > > Hello Everyone,
> > >
> > > I am trying to format decimal values the way so decimal point is display
> > > only if the number is any digits after decimal other than zero.
> > >
> > > Example:
> > > 9.000000 -> "9"
> > > 9.500000 -> "9.5"
> > >
> > > Does anyone have an idea how the format string should look like? Is it, at
> > > all, possible?
> > >
> > > Tomasz
> >
>
> >

AddThis Social Bookmark Button