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 902529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:43:55+00:00 2026-05-15T15:43:55+00:00

In the environment that my program is going to run, people use ‘,’ and

  • 0

In the environment that my program is going to run, people use ‘,’ and ‘.’ as decimal separators randomly on PCs with ‘,’ and ‘.’ separators.

How would you implements such a floatparse(string) function?

I tried this one:

    try
    {
        d = float.Parse(s);
    }
    catch
    {
        try
        {
            d = float.Parse(s.Replace(".", ","));
        }
        catch
        {
            d = float.Parse(s.Replace(",", "."));
        }
    }

It doesn’t work. And when I debugg it turns out that it parses it wrong the first time thinking that “.” is a separator for thousands (like 100.000.000,0).

I’m noob at C#, so hopefully there is less overcomplicated solution then that 🙂

NB: People a going to use both ‘.’ and ‘,’ in PCs with different separator settings.

  • 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-15T15:43:56+00:00Added an answer on May 15, 2026 at 3:43 pm

    If you are sure nobody uses thousand-separators, you can Replace first:

    string s = "1,23";  // or s = "1.23";
    
    s = s.Replace(',', '.');
    double d = double.Parse(s, CultureInfo.InvariantCulture);
    

    The general pattern would be:

    • first try to sanitize and normalize. Like Replace(otherChar, myChar).
    • try to detect a format, maybe using RegEx, and use a targeted conversion. Like counting . and , to guess whether thousand separators are used.
    • try several formats in order, with TryParse. Do not use exceptions for this.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi there I have a program that requires me to set the PATH environment
I would like to send a windows service program to our client that does
I work in an multi-site environment that's currently using Rational ClearCase for source control
I'm developing in an environment that is severely constrained, but the developers also have
I have an object in a multi-threaded environment that maintains a collection of information,
In C# there is the static property Environment.Newline that changed depending on the running
How can I best set up my PHP (LAMP) development environment so that I
I just want my apache to register some of my predefined environment so that
Environment I'm working on a C++ application that uses SQL Native Client 9.0 to
I have a string that has some Environment.Newline in it. I'd like to strip

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.