Dot instead of comma for decimal number separator?

9,542 views
Skip to first unread message

Marko D. Topic

unread,
Aug 26, 2009, 9:42:20 PM8/26/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi people,
I'm using C# and having some problems with the display of decimal
numbers. Whether I use String.Format(0:0.00) or the ToString() method
for converting floats to strings I always end up with 123,45 insead of
123.45! How to solve this?

Cerebrus

unread,
Aug 27, 2009, 3:11:15 AM8/27/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
String.Format() is a culture sensitive function. Your current culture
settings probably use a comma as decimal separator. To be sure of the
output, specify the Invariant culture as an argument.

string.Format(NumberFormatInfo.InvariantInfo, "format", args);

Vitaly Maslevskiy

unread,
Aug 27, 2009, 2:18:24 AM8/27/09
to dotnetde...@googlegroups.com
Brute force solution would be to use NumberFormatInfo as below

using System.Globalization
.....
float a = 123.45f;
NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NumberDecimalSeparator = ".";
Console.Write(a.ToString(nfi));

Are you writing asp.net? win forms app? Asking cause , decimal separator
depends on CurrentThread.CurrentUICulture.

Regards
Vitaly

2009/8/27 Marko D. Topic <mdt...@gmail.com>:

Marko D. Topic

unread,
Aug 27, 2009, 8:25:43 AM8/27/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
It works, thanks! ;)

Cerebrus

unread,
Aug 27, 2009, 10:10:23 AM8/27/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I think that should be CurrentCulture. The UICulture reflects the UI
language, while the Culture reflects the regional options (Date,
number formatting).

On Aug 27, 11:18 am, Vitaly Maslevskiy <vitaly.maslevs...@gmail.com>
wrote:

Vitaly Maslevskiy

unread,
Aug 30, 2009, 5:43:04 AM8/30/09
to dotnetde...@googlegroups.com
yeah

you absolutely right.


2009/8/27 Cerebrus <zor...@sify.com>:

Reply all
Reply to author
Forward
0 new messages