✅ "{0:C}" doesn't return the '$' symbol as it used to.

This used to return the '$' symbol, but now it doesn't. I'm using the latest version with C# in a .Net 8.0 project. Any reason for that? Example:
C#
using System;

class Program
{
public static void Main(string[] args)
{
decimal price = 19.99m;
decimal discount = 0.2m;
decimal total = price - (price * discount);

Console.WriteLine("Total: {0:C}", total);
}
}
C#
using System;

class Program
{
public static void Main(string[] args)
{
decimal price = 19.99m;
decimal discount = 0.2m;
decimal total = price - (price * discount);

Console.WriteLine("Total: {0:C}", total);
}
}
12 Replies
leowest
leowest2w ago
it returns whatever is your window currency symbol setup to if u want to change that u need to change the culture of the console for example:
CultureInfo ci = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = ci;
CultureInfo ci = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = ci;
triplemocha
triplemochaOP2w ago
I never had to use this in the past. I wonder if it's just required now to set the culture info. I got an exeception when trying that:
System.Globalization.CultureNotFoundException: 'Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-US is an invalid culture identifier.'
System.Globalization.CultureNotFoundException: 'Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-US is an invalid culture identifier.'
leowest
leowest2w ago
like I said its your window configuration you can look it up
leowest
leowest2w ago
No description
leowest
leowest2w ago
that is what determinates what symbol your console will display
triplemocha
triplemochaOP2w ago
I opened up the .csproj and changed InvariantGlobalization from true to false, and it worked fine. I'm guessing it's a .Net thing compared to the .Net framework.
leowest
leowest2w ago
it doesnt have a InvariantGlobalization in the csproj by default so u must have added it there
triplemocha
triplemochaOP2w ago
I did change the project's properties prior to programming in it. It's maybe a setting I changed accidently.
leowest
leowest2w ago
$close
MODiX
MODiX2w ago
If you have no further questions, please use /close to mark the forum thread as answered
leowest
leowest2w ago
normally the ruling is the OS currency unless u have something extra changing it glad u figured it out
triplemocha
triplemochaOP2w ago
Thanks.
Want results from more Discord servers?
Add your server