I have an ASP.NET Core 2.1 project where I am rendering some currency numbers through a Razor HTML page.
View Model
class MyModel
{
public decimal Money { get; set; } = 1.23
}
Razor Page
@model MyModel
<p>@Model.Money.ToString("C")</p>
This project is deployed to Azure App Service.
On a Windows App Service plan (and my local Windows 10 machine), this produces "$1.23" as expected. However, if I deploy the same project to a Linux App Service Plan it renders "¤1.23".
According to Google:
The currency sign (¤) is a character used to denote an unspecified currency.
Any idea what there is a difference between the two OS here? Do I need to explicitly set the culture or something on Linux?
The "C" (or currency) format specifier is used to convert a number to a string representing a currency amount. Let us see an example. double value = 139.87; Now to display the above number until three decimal places, use (“C3”) currency format specifier.
Tip: To quickly apply the Currency format, select the cell or range of cells that you want to format, and then press Ctrl+Shift+$. Like the Currency format, the Accounting format is used for monetary values. But, this format aligns the currency symbols and decimal points of numbers in a column.
CurrentCulture handles dates,currencies,sorting and formatting issues in Dot Net.
This is caused by that the linux did not configure locale.
You could set the thread culture in your program like below:
public class Program
{
public static void Main(string[] args)
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With