Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top