This is a migrated thread and some comments may be shown as answers.

Number formatting with variable decimals

5 Answers 1618 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 06 Aug 2015, 11:19 AM

Kendo version 2015.2.805

IE10 or Chrome 44

I have a Grid with edit set to Popup, and a template for editing. 

The template includes a NumericTextBox

I need to set a format that will show the number of decimals entered, but no more.

So for a value 1.23 it would show 1.23, or a value 1.2345678 would show 1.2345678. But I can't get it to work.

A format of #######0.00000000 is showing 1.23000000 and 1.2345678

A format of #######0.0####### was showing 1.23 and 1.23

A format of ########.######## is showing 1 and 1

A format of #.# is failing to display the page (which normally means a script error).

My code:

<input name="currentExchangeRate" data-role="numerictextbox" data-bind="value:currentExchangeRate" data-decimals="8" data-format="{0:#######0.0#######}" data-min="0" data-spinners="false" />

5 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 10 Aug 2015, 02:17 PM

Hello Simon,

Actually with the provided configuration code both values 1.23 and 1.2345678 are displayed correctly. Please refer to the http://dojo.telerik.com/eTIJU and let me know if I am missing something. 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simon
Top achievements
Rank 1
answered on 10 Aug 2015, 02:24 PM

The issue occurs when using the numericTextBox within a Kendo Grid using a template for the popup editor.

If I don't use a template and let Kendo generate its own numericTextBox inputs then it works correctly (that is the work-around I am currently using, though it limits what I can include in the popup window).

0
Simon
Top achievements
Rank 1
answered on 12 Aug 2015, 09:26 AM

I've tried setting up a snippet to illustrate my problem

http://dojo.telerik.com/ILAKu

 

As it stands, with format ##.##, all values display ​rounded to the nearest integer, which is wrong. The same occurs with (for example) ######0.##.

If I change the format to ​#0.##, or ######0.0# then the grid doesn't display​ at all

A format of ###0.0####### will display the grid, but clicking Edit ​doesn't open the popup.

0
Accepted
Boyan Dimitrov
Telerik team
answered on 12 Aug 2015, 01:34 PM
Hello,

Since the "#" is used by the template in order to evaluate/execute an expression, they should be escaped. Otherwise they will be seen as code block and eventually executed instead of using as format option for the numeric text box.

Please refer to  Kendo UI Templates Overview article for more information about templates. 

A solution for this case would be escaping the format option for the numeric text box as shown below:

<input name="Freight" data-role="numerictextbox" data-bind="value:Freight" data-decimals="8" data-format="{0:\\#\\#.\\#\\#}" data-min="0" data-spinners="false" />


Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Simon
Top achievements
Rank 1
answered on 12 Aug 2015, 01:46 PM
Thanks, that's sorted it :-)
Tags
NumericTextBox
Asked by
Simon
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Simon
Top achievements
Rank 1
Share this question
or