Search code examples
kendo-ui-angular2

Numeric control percentage type to show 5% instead of 0.05 on focus


is there any configuration in the control to show 5% on focus too instead of 0.05, for percentage its right to show 0.05 as value and on focus out it displays 5% but if there is a configurable switch to do the show 5% both times other than writing custom focus and blur events


Solution

  • The built-in number formatting allows to escape the '%' symbol, thus skipping the default value * 100 behavior.

    Here is how you can do this:

    @Component({
      selector: 'my-app',
      template: `
        <kendo-numerictextbox
            [value]="value"
            [format]="format"
        ></kendo-numerictextbox>
      `
    })
    
    export class AppComponent {
      public value: number = 5;
      public format: string = "#.# \\%";
    
      constructor(public intl: IntlService) {}
    }
    

    Runnable demo: http://plnkr.co/edit/Ba05nP4LCgjuKjssSJzE?p=preview

    More details about the formats can be found in the kendo-intl repo:

    https://github.com/telerik/kendo-intl/blob/master/docs/num-formatting/index.md#custom