|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
format number including + or - signHi,
Is there any formatting that adds + or - sign before number. Normally it adds - sigh if number is negative and no sign if positive. I want to add + sign when number is positive. Thank you in advance. Shailesh Shailesh,
The most simple is mostly something as A = 0 - A As you mean as a string then use the overloaded ToString with the numeric formatprovider. Cor "Cor Ligthert[MVP]" <notmyfirstn***@planet.nl> schrieb: Did you mean 'A = -A', which will cause the sign to be "swapped"?> The most simple is mostly something as > > A = 0 - A > As you mean as a string then use the overloaded ToString with the numeric I took a look at the custom numeric format strings documentation and I could > formatprovider. not come up with a formatting pattern which will cause the sign of the number to be shown regardless if it is a "+" or a "-". 'NumberFormatInfo' contains properties which will return the sign characters, but documentation states that they are only used for parsing and not for formatting. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> >> Yes, nicer with the same result of course>> A = 0 - A > > Did you mean 'A = -A', which will cause the sign to be "swapped"? > I have people seen doing this. A = -1 * A which I don't like at all. Cor I found this one that works. Never had a need for it, but it does work:
dim x as double string.Format("{0:+0;-0;0}", x) I have to credit this url: http://blogs.msdn.com/kathykam/archive/2006/03/29/564426.aspx Show quoteHide quote "Shailesh Patel" wrote: > Hi, > Is there any formatting that adds + or - sign before number. Normally it > adds - sigh if number is negative and no sign if positive. > I want to add + sign when number is positive. > > Thank you in advance. > > Shailesh > > > |
|||||||||||||||||||||||