Luke
Luke

Reputation: 443

BoundField double show as many decimal places as needed

I have a double variable assigned to a boundfield in a gridview. There will only ever be a max of 5 decimal places.

The boundfield is formatting the display to a scientific value. I'm assuming because it would default to a general format which gives the most compact of either fixed-point or scientific notation (https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring%28v=vs.110%29.aspx)

How can i format the number to show only as many decimal places as needed, up to 5. And do not show scientfic notation?

i.e. 0.00002 is currently showing as 2E-05, but I would like it to show as 0.00002. 0.002 should show as that, and not 0.00200. 1 should show that, and not 1.00000. etc.

So a format such as {0:N5} would not work. {0:N} defaults to 2 decimal places, and so would not work either.

Thanks for any help.

Upvotes: 0

Views: 1256

Answers (1)

Luke
Luke

Reputation: 443

Thanks for the advice @David W I ended up working it out anyhow. Although I couldn't find any documentation on it, you can give it proper custom formats. Therefore, the following solved my issue;

<asp:BoundField DataField="theField" DataFormatString="{0:0.#####}" />

Upvotes: 1

Related Questions