format number including + or - sign

  • Thread starter Thread starter Shailesh Patel
  • Start date Start date
S

Shailesh Patel

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
 
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 said:
The most simple is mostly something as

A = 0 - A

Did you mean 'A = -A', which will cause the sign to be "swapped"?
As you mean as a string then use the overloaded ToString with the numeric
formatprovider.

I took a look at the custom numeric format strings documentation and I could
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.
 
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
 
Back
Top