C
C#11mo ago
wilbertom

Does CultureInfo ever matter here?

I have some code that is generating some warnings:
CA1305: The behavior of 'long.ToString()' could vary based on the cu
rrent user's locale settings.
CA1305: The behavior of 'long.ToString()' could vary based on the cu
rrent user's locale settings.
My software does run under different locale settings but I don't think long.ToString() are ever displayed differently. Am I correct in thinking it doesn't matter here? Iterating all cultures, I see that they all output the same thing:
long i = 1000000000000;

foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
Console.WriteLine(i.ToString(culture));
}
long i = 1000000000000;

foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
Console.WriteLine(i.ToString(culture));
}
3 Replies
Mayor McCheese
Mayor McCheese11mo ago
The way you have it today probably doesn't matter, but consider...
MODiX
MODiX11mo ago
Mayor McCheese
REPL Result: Success
long i = 1000000000000;

foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
Console.WriteLine(i.ToString("C", culture));
}
long i = 1000000000000;

foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
Console.WriteLine(i.ToString("C", culture));
}
Console Output
¤1,000,000,000,000.00
¤1 000 000 000 000,00
$1 000 000 000 000,00
R1 000 000 000 000,00
1 000 000 000 000,00¤
1 000 000 000 000FCFA
¤1,000,000,000,000.00
GH₵1,000,000,000,000.00
¤1,000,000,000,000.00
ብር1,000,000,000,000.00
1٬000٬000٬000٬000٫00 ¤
1٬000٬000٬000٬000٫00 ¤
1,000,000,000,000.00 د.إ.‏
1٬000٬000٬000٬000٫000 د.ب.‏
1٬000٬000٬000٬000 Fdj
1.000.000.000.000,00 د.ج.‏
1٬000٬000٬000٬000٫00 ج.م.‏
1,000,000,000,000.00 د.م.‏
1٬000٬000٬000٬000٫00 Nfk
1٬000٬000٬000٬000٫00 ₪
1٬000٬000٬000٬000 د.ع.‏
1٬000٬000٬000٬000٫000 د.أ.‏
1٬000٬000٬000٬000 CF
1٬000٬000٬000٬000٫000 د.ك.‏
1٬000٬000٬000٬000 ل.ل.‏
1.000.000.000.000,000 د.ل.‏
1.000.000.000.000,00 د.م.‏
1٬000٬000٬000٬000٫00 أ.م.
1٬000٬000٬000٬000٫000 ر.ع.‏
1٬000٬000٬000٬000٫00 ₪
1٬000٬000٬000٬000٫00 ر.ق.‏
1٬000٬000٬000٬000٫00 ر.س.‏
1٬000٬000٬000٬000٫00 ج.س.
1٬000٬000٬000٬000 S
1٬000٬000٬000٬000٫00 £
1٬000٬000٬000٬000 ل.س.‏
1٬000٬000٬000٬000 FCFA
1.000.000.000.000,000 د.ت.‏
1٬000٬000٬000٬000 ر.ي.‏
¤ 10,00,00,00,00,000.00
₹ 10,00,00,00,00,000.0
¤1,000,000,000,000.00
¤1 000 000 000 000,00
$1 000 000 000 000,00
R1 000 000 000 000,00
1 000 000 000 000,00¤
1 000 000 000 000FCFA
¤1,000,000,000,000.00
GH₵1,000,000,000,000.00
¤1,000,000,000,000.00
ብር1,000,000,000,000.00
1٬000٬000٬000٬000٫00 ¤
1٬000٬000٬000٬000٫00 ¤
1,000,000,000,000.00 د.إ.‏
1٬000٬000٬000٬000٫000 د.ب.‏
1٬000٬000٬000٬000 Fdj
1.000.000.000.000,00 د.ج.‏
1٬000٬000٬000٬000٫00 ج.م.‏
1,000,000,000,000.00 د.م.‏
1٬000٬000٬000٬000٫00 Nfk
1٬000٬000٬000٬000٫00 ₪
1٬000٬000٬000٬000 د.ع.‏
1٬000٬000٬000٬000٫000 د.أ.‏
1٬000٬000٬000٬000 CF
1٬000٬000٬000٬000٫000 د.ك.‏
1٬000٬000٬000٬000 ل.ل.‏
1.000.000.000.000,000 د.ل.‏
1.000.000.000.000,00 د.م.‏
1٬000٬000٬000٬000٫00 أ.م.
1٬000٬000٬000٬000٫000 ر.ع.‏
1٬000٬000٬000٬000٫00 ₪
1٬000٬000٬000٬000٫00 ر.ق.‏
1٬000٬000٬000٬000٫00 ر.س.‏
1٬000٬000٬000٬000٫00 ج.س.
1٬000٬000٬000٬000 S
1٬000٬000٬000٬000٫00 £
1٬000٬000٬000٬000 ل.س.‏
1٬000٬000٬000٬000 FCFA
1.000.000.000.000,000 د.ت.‏
1٬000٬000٬000٬000 ر.ي.‏
¤ 10,00,00,00,00,000.00
₹ 10,00,00,00,00,000.0
Compile: 396.138ms | Execution: 395.245ms | React with ❌ to remove this embed.
Mayor McCheese
Mayor McCheese11mo ago
now it's different. 1.000.000.000.000,000 for instance. vs $1,000,000,000,000.00
Want results from more Discord servers?
Add your server