Align Currency Right by Format Line

I have DisplayFormat

in my C # code like:

[DisplayFormat(DataFormatString = "{0:C0}")]


And the output is this: USD 50

But how can I change this display format to show 50 USD

:? with a currency symbol on the right?


source to share

1 answer

This page lists all the custom string formats available for currencies, there are many links to other msdn format string strings:

Specifically, looks like what you want [DisplayFormat(DataFormatString = "{0:0C}")]

? It almost seems too simple, have you tried that already?

--- Edit ---

Ok, I thought it would be too easy. C0

means "print number (with 0

decimal places), then currency ( C

)". However, the currency model is described in more detail later on this page. Buried in this link:

  • 0 results in $ n
  • 1 leads to n $
  • 2 results in $ n
  • 3 leads to n $

So you need either currency template 1 or 3. Now you need to find a way to insert this into an attribute DisplayFormat

, hopefully there is a way to do it. If not, it should be easy to subclass it and override the tostring method to allow the currency template to be passed (unless it's a class sealed

or whatever, gross).



All Articles