Reputation: 417
I've gone over all the numbers formatting options of .Net framework , and I cannot find the formatting I need.
I have a float variable for which I need a format string ( not code ) which does the following :
If value = 1500.00 the formatted string will be : 1,500 ( and not 1,500.00 ) If value = 1500.53 the formatted string will be : 1,500.53 If value = 0.53 the formatted string will be : 0.53
So that the "n" and "N0" formats do not do the trick for me, since "n" always adds ".00" if the value is whole number because "n" it's for float numbers, and "N0" round the number to whole number even if the value is not a whole number (1500.53)
I need this as a string since I use the formatting in ASPXGridView (devexpress control) columns - DisplayFormatString attribute
Anyone can help ?
Thanks
Another thing : the number of digits after the . can vary .. for example can be : 1500.53536
Upvotes: 1
Views: 1810
Reputation: 172478
I don't have Visual Studio available right now to test it, but after reading the documentation I'm pretty sure that the following should work:
#,##0.##
EDIT: If your numbers can have more than 2 decimal places, just add an appropriate number of #
s after the dot, e.g.:
#,##0.##############
#
means: digit or empty, whereas 0
means: digit or 0. Thus, the example given will display only as many digits after the decimal point as necessary (but at most the number of #
s).
Upvotes: 5
Reputation: 103555
Look at custom numeric format strings. I think you want something like this: "##,#.##"
.
Upvotes: 1