String.format with numbers less than zero

H

hharry

Hello All,

I am using the following to format numbers precise to 2 decimal places
with thousand separators:

Double number = 100000.87;
string MyString = String.Format("{0:0,0.00}", number);
// 100,000.87
which is fine.

When the number is less than zero:
Double number = 0.8756;
string MyString = String.Format("{0:0,0.00}", number);
// 00.87
How do output 0.87 instead of 00.87 ?

Thanks in advance.
 
B

Ben Voigt [C++ MVP]

hharry said:
Hello All,

I am using the following to format numbers precise to 2 decimal places
with thousand separators:

Double number = 100000.87;
string MyString = String.Format("{0:0,0.00}", number);
// 100,000.87
which is fine.

When the number is less than zero:
Double number = 0.8756;
string MyString = String.Format("{0:0,0.00}", number);
// 00.87
How do output 0.87 instead of 00.87 ?

Thanks in advance.

Would you mind explaining when 0.8756 became less than zero?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top