Round to 4 Decimal places not working?

Doing this:

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

I want:


I get:


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.

Need Your Help

Empty string when using GSON for Java -> JSon

java json string jackson gson

Trying to convert a POJO to a Json representation , my output is quite surprising : empty !