[Mono-list] Converting float to string for a MySQL db and internationalisation

Reggie Burnett rykr@bellsouth.net
Sun, 28 Dec 2003 10:20:19 -0600


You should use a parameter for this.  The ByteFX provider handles this
internally.  It will format the doubles and floats to strings with a =
decimal
separator since the MySql database requires that.

Reggie

> -----Original Message-----
> From: mono-list-admin@lists.ximian.com [mailto:mono-list-
> admin@lists.ximian.com] On Behalf Of Jaroslaw Kowalski
> Sent: Saturday, December 27, 2003 11:19 AM
> To: yoros@wanadoo.es; Sergio Blanco Cuaresma
> Cc: mono-list mailing list
> Subject: Re: [Mono-list] Converting float to string for a MySQL db and
> internationalisation
>=20
>=20
> There's also "CultureInfo.InvariantCulture" that you may use. It is
> guaranteed to have dot as a decimal separator.
>=20
> BTW. Setting thread culture in this case is not a good idea. You =
shoule
> either use either of:
>=20
> 1. String.Format(CultureInfo.InvariantCulture, "INSERT INTO indexed
> VALUES({0:#.##});", ...)
> 2. Convert.ToString(CultureInfo.InvariantCulture, ...).
> 3. Parametrized queries (this is actually the best idea because it =
solves
> many problems you might not be even aware of + you can get some speed
> improvements depending on your data provider).
>=20
> Jarek
>=20
> ----- Original Message -----
> From: <yoros@wanadoo.es>
> To: "Sergio Blanco Cuaresma" <sergio-blanco@iespana.es>
> Cc: "mono-list mailing list" <mono-list@lists.ximian.com>
> Sent: Saturday, December 27, 2003 5:46 PM
> Subject: Re: [Mono-list] Converting float to string for a MySQL db and
> internationalisation
>=20
>=20
> > On Sat, Dec 27, 2003 at 04:29:15PM +0100, Sergio Blanco Cuaresma =
wrote:
> > > El s=E1b, 27-12-2003 a las 08:59, yoros@wanadoo.es escribi=F3:
> > > > On Fri, Dec 26, 2003 at 08:48:48PM +0100, Sergio Blanco Cuaresma
> wrote:
> > > > >
> > > > > I have a little problem and I don't know how to solve it in an
> elegant
> > > > > way, due to internationalisation (my locales are "es_ES@euro")
> when
> I
> > > > > convert from a float type to string the decimal separator is =
",",
> thats
> > > > > fantastic but I'm trying to insert that value in a MySQL =
database,
> and
> > > > > it seems to need "." as decimal separator:
> > > > >
> > > > > string sql =3D "INSERT INTO indexed VALUES ('" +
> > > > > (fileInfo.Length).ToString("#.##") + "');";
> > > > >
> > > > > How would you solve this little problem? Is there any more =
elegant
> way
> > > > > of inserting data in a MySQL database? I'm using ByteFX.Data.
> > > > >
> > > >
> > > > You can change DecimalSeparator to ".":
> > > >
> > > > using System.Globalization;
> > > > ...
> > > > NumberFormatInfo.CurrentInfo.NumberDecimalSeparator =3D ".";
> > >
> > > It seems to be read only:
> > >
> > > Excepcion: The current instance is read-only and a set operation =
was
> > > attempted
> > >
> >
> > Sorry, I didn't tested it. I have a code that does something like =
that I
> > said...
> >
> >     using System.Threading;
> > using System.Globalization;
> > ...
> >     CultureInfo ci =3D (CultureInfo) =
CultureInfo.CurrentCulture.Clone();
> >     ci.NumberFormat =3D new NumberFormatInfo();
> >     ci.NumberFormat.NumberDecimalSeparator =3D ",";
> >     Thread.CurrentThread.CurrentCulture =3D ci;
> >
> > This works for me.
> >
> > Regards,
> >
> >     Pedro
> >
> > --
> > Pedro Mart=EDnez Juli=E1
> > \  yoros@terra.es
> > )|    yoros@wanadoo.es
> > /        http://yoros.dyndns.org
> > Socio HispaLinux #311
> > Usuario Linux #275438 - http://counter.li.org
> > GnuPG public information:  pub  1024D/74F1D3AC
> > Key fingerprint =3D 8431 7B47 D2B4 5A46 5F8E  534F 588B E285 74F1 =
D3AC
> > _______________________________________________
> > Mono-list maillist  -  Mono-list@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list
> >
>=20
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list