Configuracion regional

F

Felix González

Hola!

Tengo un problema con la configuracion regional y SqlServerCe. Tengon un
numero (2,234 por ejemplo) almacenado en una BD que lo representa como
2.234, si desde mi prigrama hago un aconversion con Syste.convet.ToDoble
obtengo el numero 2234 en vez de 2,234. Como puedo convertir al número
correcto? existe alguna función para reemplazar una cadena por otra?,
remplazaria el "." por ","
No me interesa cambiar la configuración regional


Gracias
 
B

Bruce Wood

Translation:

"I have a problem with regional configuration and SqlServerCe. I have a
number (2.234 for example) stored in a database that represents it as
2.234. If in my program I do a conversion with
System.Convert.ToDouble(), I get the number 2234 instead of 2,234. How
can I convert to the correct number? Is there some function to replace
one string with another? replace the "." for a ","? I'm not interested
in changing the regional configuration."

I suspect that the problem here is that the conversion from a string to
a double value. Because the regional configuration indicates the "."
(period) as the thousands separator, and the "," (comma) as the decimal
point, ToDouble is interpreting "2.234" as 2234 rather than as a number
just a little bigger than 2.

The solution is to provide an IFormatProvider on the ToDouble
conversion:

double valor = System.Convert.ToDouble(valorCadena,
CultureInfo.InvariantCulture);

This indicates to ToDouble that it should convert the string to a
double, _not_ using the current user interface culture, but using the
"invariant culture".

Tienes que dar a ToDouble un IFormatProvider, que indica la cultura
para la conversión. Proababilmente quieres la cultura invariable,
"CultureInfo.InvariantCulture". Cuando almacenas datos de / para un BD,
es _siempre_ mejor usar InvariantCulture... asi no almacenas datos en
forma especifica a una cultura en particolar.

Ese no cambia la configuración regional del BD ni de la computadora...
solo para la conversión de cadena a doble.

Si no das un IFormatProvider a ToDouble, va a usar la cultura de la
computadora, que parece que en tu caso indica "," como separador de
decimal.
 
B

Bruce Wood

In future, a good group for this kind of question in Spanish is
microsoft.public.es.dotnet.framework, although there are always those
of us here who can reply in our crappy Spanglish. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top