[Mono-list] Numbers with ","

xavier de Blas xavi at xdeblas.com
Sat Feb 11 05:40:36 EST 2006


Hello, i thought there were only this decimal separators in different
cultures: ',' '.'

CultureInfo.InvariantCulture is not documented in my Monodoc (1.1.13)

Can you explain a bit more why to use InvariantCulture?

Thanks

On ds, 2006-02-11 at 11:28 +0100, Kornél Pál wrote:
> Hi,
> 
> You should use myDouble.ToString(CultureInfo.InvariantCulture) instead of
> assuming a specific decimal separator and replacing that to decimal point.
> 
> Kornél
> 
> ----- Original Message -----
> From: "xavier de Blas" <xavi at xdeblas.com>
> To: <mono-list at lists.ximian.com>
> Sent: Saturday, February 11, 2006 11:15 AM
> Subject: Re: [Mono-list] Numbers with ","
> 
> 
> > Hello Paulo
> >
> > When I INSERT in SQL i always insert with '.' as decimal point
> > separator, i do it like this:
> >
> > Util.ConvertToPoint(myDouble)
> >
> >
> > On util class i have:
> >
> >
> > public static string ConvertToPoint (double myDouble) {
> >    StringBuilder myStringBuilder = new StringBuilder(myDouble.ToString());
> >    myStringBuilder.Replace(",", ".");
> >    return myStringBuilder.ToString();
> > }
> >
> > //sometimes i do it as a string
> > public static string ConvertToPoint (string myString) {
> >    StringBuilder myStringBuilder = new StringBuilder(myString);
> >    myStringBuilder.Replace(",", ".");
> >    return myStringBuilder.ToString();
> > }
> >
> >
> > When I SELECT i do:
> >
> > while(reader.Read()) {
> >  myArray.Add (reader[0].ToString() + ":" +
> >  Util.ChangeDecimalSeparator(reader[1].ToString()) + ":" +
> >  (...)
> > }
> >
> > on Util class i have:
> >
> > //used for load from the database all numbers with correct decimal
> > separator (locale defined)
> > public static string ChangeDecimalSeparator(string myString) {
> >  if(myString == "") {
> >    return "0";
> >  }
> >  System.Globalization.NumberFormatInfo localeInfo = new
> > System.Globalization.NumberFormatInfo();
> >  localeInfo = System.Globalization.NumberFormatInfo.CurrentInfo;
> >
> >  StringBuilder myStringBuilder = new StringBuilder(myString);
> >  if(localeInfo.NumberDecimalSeparator != ".") {
> >    myStringBuilder.Replace(".", localeInfo.NumberDecimalSeparator);
> >  }
> >  return myStringBuilder.ToString();
> > }
> >
> >
> > This are pieces of code of Chronojump, files:
> > http://cvs.gnome.org/viewcvs/chronojump/src/sqlite/jump.cs?rev=1.15&view=log
> > http://cvs.gnome.org/viewcvs/chronojump/src/util.cs?rev=1.19&view=log
> >
> > http://gnome.org/projects/chronojump
> >
> >
> > A bondade
> >
> >
> >
> > On ds, 2006-02-11 at 00:56 +0000, Paulo Augusto wrote:
> >> In portuguese (in fact, every language i know except english), numbers
> >> are separated by a "," comma, instead of by a "." dot.
> >>
> >> So, when my mono program needs a number from an Entry():
> >> Convert.ToSingle (string);
> >> and then i want to pass that number to MySql through an sql string:
> >> float.ToString();
> >> results in a string that has a "," which brakes the sql string.
> >>
> >> Anyone has any idea on what's the best way to handle this localisation
> >> issue?
> >>
> >> I tried working around it with:
> >> string.Replace (char, char);
> >> and
> >> string.Replace (string, string);
> >> to the resulting string but i think both are broken since they do not
> >> work at all.
> >>
> >> One would think this issue would be frequent but i do not seem to be
> >> able to find any information at all anywhere about it.
> >> _______________________________________________
> >> Mono-list maillist  -  Mono-list at lists.ximian.com
> >> http://lists.ximian.com/mailman/listinfo/mono-list
> >
> > _______________________________________________
> > Mono-list maillist  -  Mono-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list
> >
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list



More information about the Mono-list mailing list