I have tried to do this conversion(decimal? to string) using information from few similar posts, but somehow failed(“G29”; replace(“0,00″,””)…) so what would be the best way to transform 91,5M decimal? to string so that we would have 91,5?
string a;
decimal? number = 91.5M;
a = number.ToString();
in this example a = 91.5 and everything is fine. But for some strange reason when I get a bunch of objects from Oracle db and try to convert them to this specific format without trailing zeros, I just can’t find a way to do this, because always the final output is 91,50 instead of 91,5
If you specifically want up to one decimal position with no leading zeros, you can try this:
Adding more
#will increase precision, but result will not contain non-significant digits.Replace
#with0in case you have to keep trailing zeroes.You also can specify the format for the separator, with a second
IFormatProviderparameter: