468,135 Members | 1,438 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,135 developers. It's quick & easy.

format number including + or - sign

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
Nov 20 '07 #1
3 1967
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

Nov 20 '07 #2
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/archi...29/564426.aspx
"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
Nov 21 '07 #3
>>
>A = 0 - A

Did you mean 'A = -A', which will cause the sign to be "swapped"?
Yes, nicer with the same result of course

I have people seen doing this.

A = -1 * A which I don't like at all.

Cor
Nov 21 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by The Biscuit Eater | last post: by
12 posts views Thread by neutrino | last post: by
6 posts views Thread by J | last post: by
3 posts views Thread by stevek | last post: by
5 posts views Thread by Subrahmanyam Arya | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.