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

yoros@wanadoo.es yoros@wanadoo.es
Sat, 27 Dec 2003 17:46:09 +0100


On Sat, Dec 27, 2003 at 04:29:15PM +0100, Sergio Blanco Cuaresma wrote:
> El sáb, 27-12-2003 a las 08:59, yoros@wanadoo.es escribió:
> > 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 = "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 = ".";
> 
> 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 = (CultureInfo) CultureInfo.CurrentCulture.Clone();
    ci.NumberFormat = new NumberFormatInfo();
    ci.NumberFormat.NumberDecimalSeparator = ",";
    Thread.CurrentThread.CurrentCulture = ci;

This works for me.

Regards,

    Pedro

-- 
Pedro Martínez Juliá
\  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 = 8431 7B47 D2B4 5A46 5F8E  534F 588B E285 74F1 D3AC