Reputation: 2961
Is it possible to perform string formatting using c#'s string interpolation with a specific CultureInfo?
For example if you are in a en-US System and want the number to be formatted with pt-PT how to I achieve that with string interpolation?
Upvotes: 0
Views: 2765
Reputation: 273565
Interpolated strings can be converted to FormattableString
s, which can be formatted with a IFormatProvider
:
var formattableString = (FormattableString)$"{1.1:C}";
var result = formattableString.ToString(new CultureInfo("pt-PT"));
// "1,10 €"
Upvotes: 3
Reputation: 1040
You can use CultureInfo.CreateSpecificCulture
for specifying the culture and the C formatter
for converting the value into a string with a currency.
double amount = 50.5;
string str = $"{amount.ToString("C", CultureInfo.CreateSpecificCulture("pt-PT"))}";
Upvotes: 3