Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo conditional formatting results in negative zero

We are using kendo’s support for conditional formatting to build custom masks. For example:

kendo.toString(value, '\\$0;-\\$0') // e. g. -$100 or $100

The problem is that kendo picks which side of the conditional formatting to use BEFORE rounding is applied. Thus we can end up with a display of negative zero:

kendo.toString(-.01, '\\$0;-\\$0') // -$0

Note that this is similar to this issue: http://www.telerik.com/forums/issue-rounding-to-zero---getting-negative-zero, however that issue is for the built-in n2 format whereas our issue is for conditional formats.

Note that in C#/.NET, the behavior of conditional formats matches what we want:

Console.WriteLine((-.01).ToString("$0;-$0")); // $0

For reference, the reason we are building masks like this is because we have user-defined “front” and “back” symbols which should go between the negative/positive sign (or parens if we are using parens for negation) and the number itself. We thus want -$100 or ($100) instead of $-100 or $(100), where "$" is a user-specified string.

Is it possible to get Kendo to behave like .NET in this regard? Is this intended behavior or a bug in Kendo?

EDIT: it looks like this can also cause issues with "positive zero" using 3-way conditional formatting:

var format = "+\\$0;-\\$0;\\$0";
kendo.toString(1, format) // "+$1"
kendo.toString(0, format) // "$0"
kendo.toString(-1, format) // "-$1"
kendo.toString(.001, format) // "+$0" (positive zero)

This too works as desired in .NET:

Console.WriteLine(0.001.ToString("+\\$0;-\\$0;\\$0")); // $0
like image 653
ChaseMedallion Avatar asked Oct 11 '16 12:10

ChaseMedallion


1 Answers

Maybe this is an intended behavior. However, you can avoid this by rounding before you apply the formatting.

kendo.toString(Math.round(-.01), "\\$0;-\\$0") //$0
like image 124
Chris Avatar answered Sep 22 '22 11:09

Chris