How do I format a number when databinding?

  • Thread starter Thread starter Alan Silver
  • Start date Start date
A

Alan Silver

Hello,

I have a repeater on a page, and one of the data items is a price. I
would like to be able to format this to ensure it has two decimal
places, but can't work out how to do it.

Suppose the ItemTemplate contains...

<li>&pound;<%#DataBinder.Eval(Container.DataItem, "priceeach")%>

I have tried adding .ToString("f") on the end of the DataBinder call,
but that gave a compiler error that there wasn't an overloaded version
of ToString() that matched.

How would I ensure that the data item is always given two decimal
places?

TIA
 
<%#DataBinder.Eval(Container.DataItem, "priceeach","{0:n}")%>

where 0 means 0th argument (only possible index in this scenario) and n
means general number with always two decimals.
 
where 0 means 0th argument (only possible index in this scenario) and n
means general number with always two decimals.

That's excellent, thank you *so* much.
 
Back
Top