Number formatting with variable decimals

6 posts, 1 answers
  1. Simon
    Simon avatar
    17 posts
    Member since:
    May 2015

    Posted 06 Aug 2015 Link to this post

    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" />

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 10 Aug 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Simon
    Simon avatar
    17 posts
    Member since:
    May 2015

    Posted 10 Aug 2015 in reply to Boyan Dimitrov Link to this post

    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).

  5. Simon
    Simon avatar
    17 posts
    Member since:
    May 2015

    Posted 12 Aug 2015 in reply to Simon Link to this post

    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.

  6. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 12 Aug 2015 Link to this post

    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!
     
  7. Simon
    Simon avatar
    17 posts
    Member since:
    May 2015

    Posted 12 Aug 2015 in reply to Boyan Dimitrov Link to this post

    Thanks, that's sorted it :-)
Back to Top
Kendo UI is VS 2017 Ready