Reputation: 2103
I'd like to format a double like this:
1.23 => 1.2
1.0 => 1
0.4 => 0.4
0 => 0
What is the corresponding string format? I'm currently using
StringFormat={}{0:#.#}
which is nice, since it leaves out a trailing zero. Unfortunatly, it turns
0 => ""
0.4 => .4
I've googled for quite some time now and find it pretty hard to find a needed string format. Would I have to adjust the culture format?
Thank you for any help!
Upvotes: 1
Views: 103
Reputation: 15
Tested Ok!
decimal d = Convert.ToDecimal("5.23");
string sOutpu = d.ToString("0.#");
Upvotes: 0
Reputation: 152491
To preserve leading zeros use
StringFormat={}{0:0.#}
However, I'm confused by the translation 1.23 => 1.3
. If you meant 1.23 => 1.2
then the format string above should work.
Upvotes: 8