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

Add One Trailing 0 to 5 decimal places

4 Answers 355 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 28 Nov 2018, 06:11 PM

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

 

4 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 30 Nov 2018, 04:24 PM
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.
0
Steve
Top achievements
Rank 1
answered on 30 Nov 2018, 04:58 PM

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

 

0
Tsvetomir
Telerik team
answered on 04 Dec 2018, 08:00 AM
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.
0
Steve
Top achievements
Rank 1
answered on 04 Dec 2018, 06:11 PM

Thanks Tsvetomir,  it's exactly what I needed.

Cheers!

Tags
NumericTextBox
Asked by
Steve
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Steve
Top achievements
Rank 1
Share this question
or