Allow multiple decimal separators

4 posts, 0 answers
  1. Mickaël
    Mickaël avatar
    7 posts
    Member since:
    Aug 2010

    Posted 25 Jul 2011 Link to this post


    I'm using the RadGridView and am very pleased with it, but I'm facing a small issue I can't resolve myself :
    My application is running with the French culture, which decimal separator is the comma (,).

    I want my users to be able to enter decimal values with either a dot (.) or comma (,) as the decimal separator so the experience is easier for them, but I don't know how to achieve that.

    What I first tried was to handle the CellValidating event of the RadGridView, manually validate the event even if a number has a dot as a decimal separator (by setting both properties e.Handled and e.IsValid to true), but I guess some upper-level internal validation occurs and my cell appears as not valid with the error message "Input was not in a correct format", which is, if I recall well, an .NET framework "Parse" exception message, which I guess you call to determine if the value is correct.

    Do you know a way to allow both dot and comma as a decimal separator ?

    Thanks for your interest in my question.
    Mickaël Derriey
  2. Rossen Hristov
    Rossen Hristov avatar
    2478 posts

    Posted 26 Jul 2011 Link to this post

    Hi Mickaël,

    Let me try to explain how number work in the .NET Framework.

    Numbers are internally represented in the same way in the memory no matter which culture you use. Our Bulgarian decimal separator is the same as yours, i.e. a comma. The American style uses a dot. But the important thing is that once the string is parsed regardless of the culture, the actual Decimal value that is obtained has the same byte representation in memory.

    So, since the .NET Framework does not offer the functionality that you require out-of-the-box, you will have to develop your own code to handle the two different decimal separators.

    One possible way to do this would be to create a custom cell editor, that will be some kind of a smart TextBox, which will accepts numbers typed with a comma and with a dot and regardless of the symbol used convert them to the desired decimal value.

    Here you can learn more about creating custom cell editors. So basically, your magic textbox editor will accept string with any kind of possible decimal separator and convert them to the correct Decimal value. The implementation of such a control is beyond the scope of Telerik support.

    I hope this helps.

    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. Mickaël
    Mickaël avatar
    7 posts
    Member since:
    Aug 2010

    Posted 26 Jul 2011 Link to this post

    Hey Ross,

    First, I want to thank you for your answer.
    Second, after struggling with this problem another couple of hours, I found a solution which works, although it may not be the "cleanest" one. In the CellValidating event, I manually replace the dot with a comma, if any is found. This way the validation passes, and I can still perform my custom validation afterwards.

    Hoping this can help someone else,
    Have a great day, and thanks again for your support,
  4. LE MEE
    LE MEE  avatar
    1 posts
    Member since:
    Apr 2009

    Posted 14 Dec 2011 Link to this post


    There is an other way do do this : using a numeric Converter
    Numeric conversion is done using local settings.

Back to Top