dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Add IsCurrency to StringExtensions

Open Arlodotexe opened this issue 2 years ago • 2 comments

Closes #72.

Adds an IsCurrency extension method to StringExtensions that bundles an easy and obvious check for if a string is a valid currency, similar to IsDecimal.

Arlodotexe avatar Dec 20 '21 18:12 Arlodotexe

@Sergio0694 Whenever you're ready on this

Arlodotexe avatar Jun 09 '22 20:06 Arlodotexe

Hi, I'd like to draw the attention to several issues with this PR and would request to consider before merging it.

Does the name IsCurrency follow the .NET naming guidelines, specifically regarding misleading names? I would expect

"USD".IsCurrency == true;
"US Dollar".IsCurrency == true;
"MX".IsCurrency == false;

Your use of the word "currency" sounds non-standard. Maybe IsCurrencyWithAmount.

What is the global / world-wide use case, apart from your specific local use? IMO dealing with currency amounts without regarding the actual currency is a source for disaster. General tutorials give formatting examples like:

// Default US Currency Format
string.Format(new CultureInfo("en-US"), "{0:C}", 1456.12155)      // $1,456.12
// Currency format for Mexico
string.Format(new CultureInfo("es-MX"), "{0:C}", 1456.12155)      // 1.456,12 Mex$

Please never ever write such code in a public application! If a price is 1,456.12 US Dollars, a customer cannot just pay 1.456,12 Mexican Pesos instead, just because he changed the language in his browser or operating system!

faiteanu avatar Jan 21 '23 12:01 faiteanu