md shahjad ali
md shahjad ali

Reputation: 11

Is there a way to display the currency code with string format?

While formatting data for excel in C#, I am using this line of code

myValue.Style.Numberformat.Format = "$#,##0.00"

It output this: $1,234.00

But I want to also display the currency code, like this: $1,234 USD or $1,234 MXN

Is there an option for currency code in string format?

Upvotes: 0

Views: 397

Answers (2)

Orace
Orace

Reputation: 8359

I'm not aware of the logic behind the Style property (ie: what is the type of myValue), but you can probably just put the currency code in the string format:

myValue.Style.Numberformat.Format = "$#,##0.00 USD";

Lookalike demo here.

Upvotes: 0

Rod
Rod

Reputation: 2346

Dropping the .00 part from your number format should eliminate the decimal portion:

myValue.Style.Numberformat.Format = "$#,##0"

As far as the units themselves (USD vs MXN) I think that's probably logic you'll need to maintain outside of the NumberFormat method call.

Upvotes: 0

Related Questions