Add One Trailing 0 to 5 decimal places

5 posts, 0 answers
  1. Steve
    Steve avatar
    41 posts
    Member since:
    Apr 2015

    Posted 28 Nov 2018 Link to this post

    HI All,

    A custom request got me spinning and wondering if any of you came across it and have a solution for me.

    A NumericTextBox in the a grid column.

    1. Show the exact value keyed in by the user.

        Eg. 12.12345, 23.55, 76.590

    2. Value could have decimal precision up to 5 places

    3. If the user enter 1.1, it should display 1.10. (showing 1 trailing 0 in the case)

    I have solution to 1 and 2, but not 3.

    I tried using template: "#=kendo.toString(OrderQuantity,'n2')#" for the column, It will show 2 decimal places like I wanted, but it's rounded and not what the user entered.

    TIA

     

  2. Tsvetomir
    Admin
    Tsvetomir avatar
    233 posts

    Posted 30 Nov 2018 Link to this post

    Hi Steve,

    By default, the number specified in the Kendo UI NumericTextBox is rounded to the second digit. This can be modified according to your preferences by using the decimals property. Afterward, you can set the format property to five digits precision.

    Here is an example of a numeric textbox with 5 digit precision. 

    $(".numeric").kendoNumericTextBox({
      format: "{0:0.00000}",
      decimals: 5
    });

    You can find the corresponding Dojo sample at:

    https://dojo.telerik.com/uqEwECAX

    If this is not the exact scenario you are willing to achieve or if the approach in the Dojo is not the same as yours, you can share further information on your specific set-up so we can provide additional suggestions. 


    Kind regards,
    Tsvetomir
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Steve
    Steve avatar
    41 posts
    Member since:
    Apr 2015

    Posted 30 Nov 2018 in reply to Tsvetomir Link to this post

    Thanks Tsvetomir, it's close but not exactly what I wanted to do. 

    The 5 digits precision are correct by allowing the user to see what they entered

    but if the user entered 1.1, I'm hoping to see 1.10 instead of 1.10000.  Is this possible to do?

    Steve

     

  4. Tsvetomir
    Admin
    Tsvetomir avatar
    233 posts

    Posted 04 Dec 2018 Link to this post

    Hi Steve,

    The format property can be modified into something similar to: 

    $(".numeric").kendoNumericTextBox({
      format: "{0:0.00###}",
      decimals: 5
    });

    This would result into converting the 33.1 to 33.10. The downside is that if the user enters 33.590 it will be converted to 33.59. The edge case is only for the numbers ending with a "0" and longer than 2 decimals. The number 33.3596 will be saved as-is. 

    In case you would like to overcome this behavior, you can introduce a new property in the model, responsible for holding the precision of the number entered. Another approach would be to save the input as a string in the data source. 

    If you have issues implementing any of the approaches listed above, let me know. 


    Kind regards,
    Tsvetomir
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Steve
    Steve avatar
    41 posts
    Member since:
    Apr 2015

    Posted 04 Dec 2018 in reply to Tsvetomir Link to this post

    Thanks Tsvetomir,  it's exactly what I needed.

    Cheers!

Back to Top