Jayesh Jayakumar
Jayesh Jayakumar

Reputation: 29

How can we format a currency using culture group size in Kendo numeric text box?

I am using Kendo numericTextBox to display the currency. I have a requirement to format the value based on the currency selected. I am able to format the currency correctly for "en-US" and "de-DE" but I'm having trouble to format the currency correctly for culture have different group size.

All the example and sample in Kendo blog are on "en-US" and "de-DE" which have similar group size.

For "en-US" currency groupSize property is [3] what means that each group will be separated after 3 digits e.g. 1,000,000. But for some other culture which have different grouping, e.g. "en-IN" which have the 'groupSize' equals [3,2,0], kendo still group the number in group of 3 only: 1,000,000, while we expect the grouping to be 3 digits then separator then group of 2 digits etc.: 10,00,000.

Can anyone help me out on this?

Here is my code sample: http://dojo.telerik.com/@jayesh-jayakumar/AtojA/8

Upvotes: 1

Views: 906

Answers (1)

Jarosław Kończak
Jarosław Kończak

Reputation: 3407

So the problem is you are using old KendoUI version without this feature implemented. Here is a snippet with newest kendo version and it looks that it behaves diffrent for en-IN: http://dojo.telerik.com/aqEwun

However I'm not sure if this is exacly how it works in this culture cause it creates only 2 groups of digits as you can see on my example (from decimal separator it is group of 2, group of 3 and rest of digits).

EDIT:

So as you mentioned you would like to have different behavior that this in example (starting from decimal point one group of 3 digits and then groups of 2). It seems it's a bug and maybe telerik will fix it one day. Until then, you can change groupSize value in culture object from [3, 2, 0] to [3, 2] to achieve what you want.

To fix it globally in all linked cultures you can use following code:

  for(var i in kendo.cultures){
    var culture = kendo.cultures[i];
    if(JSON.stringify(culture.numberFormat.groupSize) === '[3,2,0]'){
      culture.numberFormat.groupSize = [3, 2];
    }
    if(JSON.stringify(culture.numberFormat.currency.groupSize) === '[3,2,0]'){
      culture.numberFormat.currency.groupSize = [3, 2];
    }
    if(JSON.stringify(culture.numberFormat.percent.groupSize) === '[3,2,0]'){
      culture.numberFormat.percent.groupSize = [3, 2];
    }
  }

PS. You may consider use better array comparing function than JSON.stringify().

Updated snippet: http://dojo.telerik.com/aqEwun/3

Upvotes: 0

Related Questions