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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With