This is a migrated thread and some comments may be shown as answers.

Grid data looses decimal precision in ASP MVC

4 Answers 574 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Avinash
Top achievements
Rank 1
Avinash asked on 08 Feb 2016, 05:29 PM

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

4 Answers, 1 is accepted

Sort by
0
Avinash
Top achievements
Rank 1
answered on 09 Feb 2016, 05:08 PM

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.

0
Kostadin
Telerik team
answered on 10 Feb 2016, 08:34 AM
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
0
Avinash
Top achievements
Rank 1
answered on 10 Feb 2016, 03:46 PM

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/

0
Kostadin
Telerik team
answered on 12 Feb 2016, 11:42 AM
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
Tags
Grid
Asked by
Avinash
Top achievements
Rank 1
Answers by
Avinash
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or