Menu

Culture Bugs in .NET: Why 19.99 Became 1999 on the Server
📰

Culture Bugs in .NET: Why 19.99 Became 1999 on the Server

DEV Community: dotnet·rahib khan·about 18 hours ago
#V38pMooK
#devtodotnet#devto#dev#culture#paid
Long article (2369 words) — no AI summary yet.
Reading 0:00
15s threshold

Read time: 9 minutes

An invoice import runs every night.

On my laptop, invoice INV-1001 is 19.99.

On the new server, the same file says it is 1,999. The paid total is a hundred times too big.

I open the code. It is one line: decimal.Parse(parts[1]) . Nothing looks wrong.

The cause: the server has different regional settings, and decimal.Parse quietly uses them.

The short answer

In .NET, methods like decimal.Parse , ToString , ToUpper and string interpolation use the current culture unless you pass one. The current culture comes from the machine or the user account, so the same code gives different results on different machines. For data that programs read and write (files, APIs, databases), pass CultureInfo.InvariantCulture and use ordinal string comparison. Use the user's culture only for text a person reads.

This post shows the bug in a small invoice import, the fix, and three holes I found while testing the fix. All output below comes from .NET SDK 11.0.100 (runtime 11.0.0) on Windows 10.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.