Connecting Tech Pros Worldwide Forums | Help | Site Map

Format a field into currency

peter@eway.com.au
Guest
 
Posts: n/a
#1: Apr 16 '07
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>

=?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=
Guest
 
Posts: n/a
#2: Apr 16 '07

re: Format a field into currency


When requesting the data from the database, divide it by 100. For example:
SELECT CAST(cents AS money) / 100 AS dollars
FROM Table

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


"peter@eway.com.au" wrote:
Quote:
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>
>
>
berg
Guest
 
Posts: n/a
#3: Apr 17 '07

re: Format a field into currency


On Apr 17, 1:10 am, Peter Ritchie [C# MVP] <PRS...@newsgroups.nospam>
wrote:
Quote:
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#
>
>
>
"p...@eway.com.au" wrote:
Quote:
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.
>
Quote:
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.
>
Quote:
Any idea how to easily format this so it displays correctly.
>
Quote:
Thanks in advance.
>
Quote:
Peter.
>
Quote:
<asp:TemplateField HeaderText="Recurring Amount"
SortExpression="RecurringPaymentAmount">
<ItemTemplate>
<asp:Label ID="lblRecurringPaymentAmount" runat="server"
Text='<%# Bind("RecurringPaymentAmount", "{0:c2}") %>'></asp:Label>
</ItemTemplate>
<asp:TemplateField>- Hide quoted text -
>
- 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?

Closed Thread