On Wed, 2006-02-08 at 15:44 +0100, Jan Waiz wrote:
> I have a Problem using the correct Group- and Decimalseparator in when
> trying to parse a string that contains a numeric value like:
>
> string    sNum = “12,34”;
> decimal nNum = decimal.Parse( sNum ); // => 12,34
> 
> Now I am trying this:
>
> string    sNum = “12.34”;
> decimal nNum = decimal.Parse( sNum ); // => 1234
> 
> I test a lot with NumberFormatInfo without successful Result. 

Using NumberFormatInfo is the right approach, but you're not actually
using NumberFormatInfo.  You need something like this:

        decimal nNum = decimal.Parse ("12.34",
          System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

Note that we're passing a NumberFormatInfo as the 2nd parameter to
decimal.Parse.  You could pass any NumberFormatInfo instance, such as
`new CultureInfo ("en-US").NumberFormat` or a custom instance, and it
would use the provided NumberFormatInfo information to parse the string.

 - Jon


_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to