문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top