Mihir Shah
Mihir Shah

Reputation: 988

string.Format is not giving correct output when INR currency symbol (Rs.) come to display

While display bank transaction data to INR currency symbol (Rs.), output is not coming correct way. I need to display currency symbol along with 2 decimal points with thousand separator.

I have tried so far1:

column.PropertiesEdit.DisplayFormatString = string.Format("{0} #,0.00", Model.CurrencySymbol);

I have used DevExpress MVC GridView.

Current output when INR Currency:

Rs2500. 00

Expected output when INR Currency:

Rs. 2,500.00

Its working fine for other currency, i.e. $ 1,500.00 or any currency.

1 Here Model.CurrencySymbol is type of string, i.e. "$" OR "Rs." etc, according to currency filter.

Upvotes: 1

Views: 448

Answers (2)

nempoBu4
nempoBu4

Reputation: 6631

Your Model.CurrencySymbol string can have some symbols that can be interpreted as format specifier symbols.
You can use literal string delimiter ('string', "string") so your currency symbol string will be copied to the result.
For example:

column.PropertiesEdit.DisplayFormatString = string.Format("'{0}' #,0.00", Model.CurrencySymbol);
                           //Here comes string delimiters: ↑   ↑

Also you can use escape character (\) to escape the dot symbol (.) in your Model.CurrencySymbol.
For example:

column.PropertiesEdit.DisplayFormatString = string.Format("{0} #,0.00", Model.CurrencySymbol.Replace(".", @"\."));

Upvotes: 1

sangram parmar
sangram parmar

Reputation: 8736

just change your "Rs." symbol to "Rs\\." to escape "."(to not include in numeric format).

Everything working fine on do this.

Upvotes: 0

Related Questions