.Net Convert numbers from one culture to another

In .Net (VB is more specific, but it doesn't really matter), is there a way to change the format of a number from one culture to another strictly through this type of number?

The problem is this: in English, this number, for example, 123.45. If in Sweden the number is 123.45

Is there a way to convert 123.45 to 123.45 without having to convert it to a string (and then use formatting methods) and then convert it back to the correct type (single, double, etc.)?

+4
source share
3 answers

This will not be the case of converting to a string, and then back to the correct type - quite the opposite.

There is no formatting information in the issue itself. A float is a float, this is a float. This is only when analyzing or formatting the culture becomes relevant.

If you already have a float value, just format it appropriately based on who reads it.

+6
source

Leave it as a number. Modify the cultural information in the stream and it will be displayed accordingly without the need for conversion.

eg.

Thread.CurrentThread.CurrentCulture = New CultureInfo("se-SE") Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture 

Never try to format numbers or dates in strings, or you will be on your way to hell.

UPDATE: John makes you think about the comments, you will find out whether this applies to your situation or not.

+3
source

You can use the NumberFormatInfo class to do this.

0
source

All Articles