Disable auto round for decimal

10 posts, 1 answers
  1. Flavio
    Flavio avatar
    22 posts
    Member since:
    Jan 2011

    Posted 27 Mar 2012 Link to this post

    Hi,

      I updated my applications to new version, Telerik 2012 Q1 but before I was using Telerik 2012. When I was testing the application I saw a grid doesn't display the value of the previous version of Telerik. When I set a value 12.379 the value is rounded to 12.38 and in the previous version I set a value 12.379 and it keeps the value.
     I'd like know how to do disable the round option when I set values like 12.379?

    Example attached.

    Thanks!
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 30 Mar 2012 Link to this post

    Hello Flavio,

    Thank you for writing.

    GridViewDecimalColumn has a property called DecimalPlaces which determines how many decimals should be displayed when the cell is edited. Additionally, there is a FormatString property of the column, which is used to format the cells when they are not in edit mode:
    ((GridViewDecimalColumn)radGridView1.Columns["MyColumnName"]).DecimalPlaces = 5;
    ((GridViewDecimalColumn)radGridView1.Columns["MyColumnName"]).FormatString = "{0:#,0.0000}";

    I hope this helps.

    Regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. Alejandro
    Alejandro avatar
    2 posts
    Member since:
    Oct 2012

    Posted 01 Oct 2012 Link to this post

    it does not work ... any idea?? is still auto rounding
  4. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 04 Oct 2012 Link to this post

    Hi Alejandro,

    Thank you for writing.

    You need to set the DecimalPlaces and the FormatString of the column with the number of decimal places desired. For example in my previous post I am allowing up to 5 decimal places, so any extra one will be rounded.

    I hope this helps.
     
    Kind regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  5. Aaron
    Aaron avatar
    9 posts
    Member since:
    Jun 2009

    Posted 20 Jun 2013 Link to this post

    The solution you are proposing is not flawless, because if you put a number like 28.9999999999999 will get round to 29, so it is not good if your data needs to be accurate and without rounding.
  6. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 25 Jun 2013 Link to this post

    Hi Aaron,

    Depending on your requirements, you can set the corresponding DecimalPlaces and FormatString. If you do not want rounding just set it the desired DecimalPlaces and FormatString:
    ((GridViewDecimalColumn)radGridView1.Columns["DecimalColumn"]).DecimalPlaces = 5;
    ((GridViewDecimalColumn)radGridView1.Columns["DecimalColumn"]).FormatString = "{0:N5}";

    Make sure you column DataType supports decimals as well i.e. decimal, double.

    Regards,
    Stefan
    Telerik
    RadChart for WinForms is obsolete. Now what?
  7. Saif
    Saif  avatar
    30 posts
    Member since:
    Apr 2014

    Posted 13 Jan 2016 in reply to Aaron Link to this post

    I'm having the same problem, even if i apply the decimalplaces and formatstring the value that i entered is still rounding
  8. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 15 Jan 2016 Link to this post

    Hello Saif,

    Can you please provide an example - what value are you entering, and also what column type you use and the settings in the DecimalPlaces and the FormatString properties?

    Regards,
    Stefan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  9. Mary
    Mary avatar
    13 posts
    Member since:
    Jul 2014

    Posted 03 Sep 2018 Link to this post

    Could it be that the data type of your underlying DataSource column is Int rather than Decimal? The reason that my decimal columns were rounding up (in spite of setting the DecimalPlaces and FormatString properties) was because the columns in my DataTable were Int32.
  10. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3559 posts

    Posted 04 Sep 2018 Link to this post

    Hello, Mary,         

    For numeric fields RadGridView offers GridViewDecimalColumn. You can specify the DataType, DecimalPlaces and FormatString properties of the GridViewDecimalColumn. Thus, the value will be integer and it is not expected to be rounded. If you are still experiencing any undesired behavior it would be greatly appreciated if you can provide a sample code snippet with which I can replicate the problem on my end and make an adequate analysis of the precise case.

    I hope this information helps. If you have any additional questions, please let me know.  
     
    Regards,
    Dess
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top