Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 961295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:19:15+00:00 2026-05-16T01:19:15+00:00

I have some issues with number <-> string conversion i cannot sort out. We

  • 0

I have some issues with number <-> string conversion i cannot sort out.

We have written a serialization framework which uses several xml serialization techniques. But i have seen some inconsistent number conversions in the generated output:

using:

var c = TypeDescriptor.GetConverter(double);
var s = c.ConvertToString(value);

and

var c = TypeDescriptor.GetConverter(double);
return c.ConvertFromString(value.Value);

I get strings with comma separator like 3,33 and conversion back to double works, but will conversion back to double also work in another country which uses dot as separator? (I am in germany, we use comma, but besides that, i want the dot seperator)

Then in another part of the code i convert the doubles in some structs directly by adding it to a XElement:

data.Add(new XElement("x", vector.x));

The XElement constructor converts the double to a string with dot like “3.33”.

It gets really strange, when i want to convert this string back to a double:

Double.TryParse(item.Value, out value.x);

and

value.x = Convert.ToDouble(item.Value);

both ignore the dot and i have a double value of 333!?

so i tried it there also with the TypeConverter code, but it gives me an exception, that “3.33” is no valid string for the double converter…

Now what i really need is a number <-> string conversion which always uses dot separator and also parses it righ, regardless the culture/localization settings…

i am lost.. which should i use? i even tried things like:

    NumberFormatInfo provider = new NumberFormatInfo();

    provider.NumberDecimalSeparator = ".";
    provider.NumberGroupSeparator = " ";
    provider.NumberGroupSizes = new int[] { 3 };

    foreach (var item in CultureInfo.GetCultures(CultureTypes.AllCultures))
    {
        item.NumberFormat = provider;
    }

but it didn’t help..
thanks for any hint..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:19:16+00:00Added an answer on May 16, 2026 at 1:19 am

    An example on how to “fix” this issue. Assuming this is the original:

    double ParseString(string s)
    {
         return double.Parse(s);
    }
    

    this is one type of fix

    double ParseString(string s)
    {
         return double.Parse(s, CultureInfo.InvariantCulture);
    }
    

    here is another you can use if you have a large number of Parses()

    double ParseString(string s)
    {
         // Save off previous culture and switch to invariant for serialization.
         CultureInfo previousCulture = Thread.CurrentThread.CurrentCulture;
         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
    
         double result = double.Parse(s, CultureInfo.InvariantCulture);
    
         Thread.CurrentThread.CurrentCulture = previousCulture;
    
         return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some issues in setting the classpath for the a project for which
There are a number of issues i'm having, all being related. Some I have
I have created a JPanel which contains an arbitrary number of JLabels, laid out
I have some issues with a PHP file that is not working properly. The
I have some issues with my EJB 3 timer where it is launched more
I'm have some issues adding a class to 2 navigation links on a theme.
I seems to have some issues in order to compile gproc from uwiger. I
Im starting with CoCos2d development and I think I have some issues with nodespace,
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
I am integrating PayPal in my website But I have some issues in it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.