Reputation: 4116
I have been trying to display a double with a '%' sign.
I cant use "P2"
string format due to the fact that we want user to enter percentage that is saved as it is.
Hence we did use .DataFormatString = "{0}%"
to display a '%' sign at the end of our data.
but this displays data like 1.2300000000%.
Now to truncate trailing zeros we were tempted to use .DataFormatString = "G29"
which would effectively remove all unnecessary zeros but now how do we add a "%"
sign at the end of string ?
Can we somehow club two string formats to use "G29"
with "%"
sign ?
I have made various attempts to format this, but none have been on target, might be very simple one that I am missing..
Upvotes: 0
Views: 124
Reputation: 4808
You were on the right track:
string result = string.Format("{0:G29}%", 1.2300000000);
Upvotes: 3