Format a field into currency

  • Thread starter Thread starter peter
  • Start date Start date
P

peter

Hi, I currently have a field which stores an amount in the database as
an integer. It is stored as cents, so 155 in the databse it is really
$1.55.

Problem is when I Bind it to a datagrid using the Text='<%#
Bind("RecurringPaymentAmount", "{0:c2}") %>'>, it displays as $155.00
instead of $1.55.

Any idea how to easily format this so it displays correctly.

Thanks in advance.

Peter.

<asp:TemplateField HeaderText="Recurring Amount"
SortExpression="RecurringPaymentAmount">
<ItemTemplate>
<asp:Label ID="lblRecurringPaymentAmount" runat="server"
Text='<%# Bind("RecurringPaymentAmount", "{0:c2}") %>'></asp:Label>
</ItemTemplate>
<asp:TemplateField>
 
When requesting the data from the database, divide it by 100. For example:
SELECT CAST(cents AS money) / 100 AS dollars
FROM Table
 
When requesting the data from the database, divide it by 100. For example:
SELECT CAST(cents AS money) / 100 AS dollars
FROM Table

--
Browsehttp://connect.microsoft.com/VisualStudio/feedback/and vote.http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#








- Show quoted text -

Thanks Peter, I did that, tho when i click to edit the row (in the
grid view) it displays the value in the ItemEditField template as
150.0000 for some reason.

any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top