Simon
Simon

Reputation: 492

How to modify currency format using DataFormatString in GridView

How would I display the value, for example:

851839.850000

To show its currency equivalent with comma and period formatting:

£851,839.85

by using DataFormatString? Currently I have £{0:c2}, but clearly this is not enough, as it gives me

£851839.850000

Upvotes: 2

Views: 13175

Answers (4)

Fred
Fred

Reputation: 1

TO display in text box..Try

textbox.text = Format(Value,"$#,###.00")

Upvotes: 0

Pankil Agrawal
Pankil Agrawal

Reputation: 101

Define culture like

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" 
    CodeFile="Search.aspx.cs" Inherits="Search_aspx" Title="Search"  
    UICulture="hi-IN" Culture="hi-IN" %>

Find culture code from this list

Upvotes: 2

Simon
Simon

Reputation: 492

It turned out that the original value that was being bound was actually in a string format. Simpling making sure it was incoming as a Decimal allowed the formatting:

£{0:C}

to work precisely as expected and format into a correct decimal value with a £(British Sterling) to be placed before the value.

Upvotes: 5

Ann L.
Ann L.

Reputation: 13965

You could try £{0:N2}, see if that works.

Currency formatting is based on the current NumberFormatInfo. C2 ought to work for you, depending on your current culture, but since it doesn't you might want to look at the NumberFormatInfo information.

There's more about currency formatting here: The Currency ("C") Format Specifier

Upvotes: 0

Related Questions