Parse currency with an explicit culture in C#

A currency string carries formatting conventions as well as digits. Decide which culture the input uses before parsing it. The machine's current culture can interpret the same punctuation differently.

Use decimal for the parsed amount and TryParse for expected invalid input. The example accepts an Australian dollar amount and prints an invariant numeric representation.

Parse the value

Requires a .NET SDK. Create a console project with dotnet new console -n CurrencyDemo, replace Program.cs with this code, then run dotnet run --project CurrencyDemo.

C#
using System.Globalization;

var input = "$1,234.50";
var culture = CultureInfo.GetCultureInfo("en-AU");

if (!decimal.TryParse(input, NumberStyles.Currency, culture, out decimal amount)) {
	Console.Error.WriteLine("Enter a valid Australian dollar amount.");
	return;
}

Console.WriteLine(amount.ToString("0.00", CultureInfo.InvariantCulture));

The expected output is 1234.50. Replace the input with not an amount to exercise the validation branch without an exception.

Keep parsing separate from business rules

NumberStyles.Currency allows currency formatting, including conventions such as grouping and negative amounts. It does not establish the currency's identity, require exactly two fractional digits, or reject amounts outside your application's range. Validate those rules after parsing and carry an explicit currency code alongside the value when multiple currencies are possible.

Choose a culture from the input contract or the user's selected locale. Do not guess by trying cultures until one succeeds. For machine-to-machine values, agree on an invariant numeric format and a separate currency code instead of accepting display strings.

Official references

Parsing Numeric Strings in .NET - .NET
Learn about parsing numeric strings in .NET. Learn how to parse with format providers, NumberStyles enumeration values, and Unicode digits.
https://learn.microsoft.com/en-us/dotnet/standard/base-types/parsing-numeric
Parsing numeric strings

Author: Herman Schoenfeld