|
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 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 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 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 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 > > > > > |
|||||||||||||||||||||||