|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Another String.Format() QuestionHello 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 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 quoteHide 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 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 -- Show quoteHide quoteMilosz 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 > > Small bug - double quotes :)
it should be: decimal x = 19.5M; string formatedValue = x.ToString("0.########"); Pozdro Tomek :D -- Show quoteHide quoteMilosz Skalecki MCP, MCAD "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 > > > > Good call. Thanks.
Bryan Phillips MCSD, MCDBA, MCSE Blog: http://bphillips76.spaces.live.com Show quoteHide 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 > > > > >
Other interesting topics
Mutually Exclusive C# Method
Errors in Page directive Graph control Hover effects, IMessageFilter not working as expected .NET 2.0 Reflection Problem vs framework 1.1x - how to get the fields of a given Structure in the sa session variable and asynchrous call Regex - words extraction Image Recommendations .NET 2.0 problem: 100% cpu usage in mscorwks.dll!CreateApplicationContext ISerializable and SerializableAttribute |
|||||||||||||||||||||||