Grid data looses decimal precision in ASP MVC

5 posts, 0 answers
  1. Avinash
    Avinash  avatar
    52 posts
    Member since:
    Jan 2016

    Posted 08 Feb Link to this post

    I have a decimal property in my modal which keeps loosing decimal precision whenever i bind it to Kendo grid.

    Here is the example.

    If the value is 501.14, grid will display 501.14. (correct)
    If the value is 501.10, grid will display 501.1    (wrong, it should have displayed 501.10)
    If the value is 501.00, grid will display 501       (wrong, it should have displayed 501.00)

    I know i can easily solve this issue by using 'Format' function in the grid, i.e. .Format("{0: n2}") but the issue is i won't know how many decimal places i will be getting during the call so i won't be able be to hard code the value in 'Format' function. Also, i need to display all the decimal places even though it is just 0 at the end i.e .00 or .10. 

     Any suggestion how i can fix this issue?

    Thanks

    Avinash

  2. Avinash
    Avinash  avatar
    52 posts
    Member since:
    Jan 2016

    Posted 09 Feb in reply to Avinash Link to this post

    In order to display decimal precision the workaroudn  we have used is to make datatype of the property to string so that it displays the value as it is. However this has the issue while sorting the column, since it sorts it as string value instead of decimal.

    Thanks.

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 10 Feb Link to this post

    Hi Avinash,

    A possible solution is to use a Custom format and use # which is a digit placeholder .Please check out the following sample.

    Regards,
    Kostadin
    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
  5. Avinash
    Avinash  avatar
    52 posts
    Member since:
    Jan 2016

    Posted 10 Feb in reply to Kostadin Link to this post

    Kostadin,

    I don't think that fixes my issue. You can see here: http://dojo.telerik.com/AyUdO

    As i mentioned on my second comment, the workaround was to make string datatype for that field so that it doesn't looses decimal precision. The only issue with this is the SORTING. When i sort the column once i make it as string data type, it doesn't seem to sort properly. Is there anyway we can sort the string column same as the numeric type. I found this solution where the user has used 'compare' function on Sortable but i couldn't use it since i couldn't find any implementation of it in ASP MVC. http://jsfiddle.net/OnaBai/H4U7D/3/

  6. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 12 Feb Link to this post

    Hi Avinash,

    At the moment setting a custom sortable compare function is not possible in the MVC Wrappers. This feature is not planned for implementation in the MVC wrappers, because even if implemented it won't be able to handle server operations.
    I am afraid you need to either add some number format without changing it or represent the number values as string in case you are using an MVC wrappers.

    I hope this information helps.

    Regards,
    Kostadin
    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready