Reputation: 911
I'd like to achieve the following results for input in C#. How to do that?
10.000000 -> 10.00
10.200000 -> 10.20
10.254550 -> 10.25455
Thanks in advance.
Upvotes: 2
Views: 125
Reputation: 125620
value.ToString("0.00####################");
Prints exactly what you need for all your sample inputs.
Both 0
and #
are part of custom numeric format pattern. You can read what they mean on msdn: Custom Numeric Format Strings.
Upvotes: 5
Reputation: 28403
Try this
string s = "10.254550";
Response.Write(Convert.ToDecimal(s).ToString("#.00##"));
#
will consider only digits except zeroUpvotes: 2