Domanda

Doing this:

double dblRateEvalResult = -0.52;
string strNewResult = dblRateEvalResult.ToString("000.####").TrimStart('-');

I want:

000.5200

I get:

000.52

What am I doing wrong?

È stato utile?

Soluzione

You need 0 custom specifier instead of #

string str =  dblRateEvalResult.ToString("000.0000").TrimStart('-');

(In your code you are trying to assign string to a double value, I guess this is a typo)

See: The "0" custom format specifier - Custom Numeric Format Strings

If the value that is being formatted has a digit in the position where the zero appears in the format string, that digit is copied to the result string; otherwise, a zero appears in the result string.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top