Kendo.toString number format not working

637 views Asked by At

Below is my directive

app.directive("numberformatDirective", function ($kWindow) {       
        return {            
            require: "ngModel",
            link : function(scope,elem,attr,ctrl)
            {             

                function parsedata(text) {
                    return kendo.toString(text, "#,##0.00");
                }

                ctrl.$parsers.push(parsedata);
                ctrl.$formatters.push(parsedata);
            }

        }

    })

When I enter any text to my input field, number is not formatted. If I do the same from controller, Its working as expected.

Controller:

        $scope.netAmount = kendo.toString(121454, "#,##0.00");

Above snippet works well from controller. But

Expected output from the directive is '1,214.54', but I always get as 12145.

Please help..

1

There are 1 answers

0
Riyas Nawab On

I did a blunder mistake. I didnt parse the input value to Float.

app.directive("numberformatDirective", function ($kWindow) {       
        return {            
            require: "ngModel",
            link : function(scope,elem,attr,ctrl)
            {             

                function parsedata(text) {
                    return kendo.toString(parseFloat(text), "#,##0.00");
                }

                ctrl.$parsers.push(parsedata);
                ctrl.$formatters.push(parsedata);
            }

        }

    })