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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:56:41+00:00 2026-06-10T11:56:41+00:00

There is an article on Single.TryParse over at MSDN with this example code: http://msdn.microsoft.com/en-us/library/26sxas5t%28v=vs.100%29.aspx

  • 0

There is an article on Single.TryParse over at MSDN with this example code:
http://msdn.microsoft.com/en-us/library/26sxas5t%28v=vs.100%29.aspx

// Parse a floating-point value with a thousands separator.
value = "1,643.57";
if (Single.TryParse(value, out number))
    Console.WriteLine(number);
else
    Console.WriteLine("Unable to parse '{0}'.", value);

Problem is in the article the TryParse returns true and the string is converted, but when I try it, it’s false. How do I fix this?


UPD: To simplify parsing, these two lines can be used:

NumberStyles style = System.Globalization.NumberStyles.Any;
CultureInfo culture = CultureInfo.InvariantCulture;

This setting allows for negative floats and strings with leading and trailing space characters to be parsed.

  • 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-06-10T11:56:43+00:00Added an answer on June 10, 2026 at 11:56 am

    you need to set culture like this

    using System.Globalization;
    
    string value = "1345,978";
    NumberStyles style = System.Globalization.NumberStyles.AllowDecimalPoint;
    CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("fr-FR");
    if (Single.TryParse(value, style, culture, out number))
       Console.WriteLine("Converted '{0}' to {1}.", value, number);
    else
       Console.WriteLine("Unable to convert '{0}'.", value);
    

    from msdn : Single.TryParse Method (String, NumberStyles, IFormatProvider, Single%)

    or

    float usedAmount;
    // try parsing with "fr-FR" first
    bool success = float.TryParse(inputUsedAmount.Value,
                                  NumberStyles.Float | NumberStyles.AllowThousands,
                                  CultureInfo.GetCultureInfo("fr-FR"),
                                  out usedAmount);
    
    if (!success)
    {
        // parsing with "fr-FR" failed so try parsing with InvariantCulture
        success = float.TryParse(inputUsedAmount.Value,
                                 NumberStyles.Float | NumberStyles.AllowThousands,
                                 CultureInfo.InvariantCulture,
                                 out usedAmount);
    }
    
    if (!success)
    {
        // parsing failed with both "fr-FR" and InvariantCulture
    }
    

    Answered over here : C# float.tryparse for French Culture

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I installed haml-mode in my Emacs follow this article http://www.emacswiki.org/emacs/HamlMode There is my code
There is this MSDN article about spcial characters in WPF/XAML : But those Things
I have an array filled with paths looking like this: library/main/single/list.php library/article/grid/thumbs.php library/footer/tiny.php These
I'm implementing an API using authentication based on this article: http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/ And this related
In an article http://dev.mysql.com/tech-resources/articles/4.1/prepared-statements.html , it says the followings: There are numerous advantages to
I found this older article how-to-monitor-the-computers-cpu-memory-and-disk-usage-in-java and wated to ask, if there is something
Take the following article for example: http://weblogs.asp.net/psteele/archive/2009/11/23/use-dependency-injection-to-simplify-application-settings.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+dotnetmvp+%28Patrick+Steele%27s+.NET+Blog%29 I don't see what benefit there is
few links on Internet (ex: http://drdobbs.com/article/print?articleId=232300575&siteSectionName= http://www.hydrogenaudio.org/forums//lofiversion/index.php/t74268.html ) point out that there is a
I believe this is an AutoMapper basics question: I have an single article Entity
The Short Version: I want a single, comprehensive MSDN Library, up-to-date and integrated with

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.