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

Value always rounded

3 Answers 1201 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Lucas
Top achievements
Rank 1
Lucas asked on 14 Sep 2020, 02:33 PM

I'm facing an issue trying to show a percentage in numeric textbox, when I set the value for something like '2.74' it shows me '3' and the decimals are ignored. I already tried some of the solutions that i found on google, like set the 'round' attribute to false or set the 'decimals' attribute to the desired value, but nothing seems to work. 

Am I doing something wrong? If so, can someone show me the error?

<kendo-numerictextbox
*ngIf="servicoExibido.servicoLightModel.valPercCustos === 'P';else currency"
[format]="'p2'"
[(ngModel)]="porcentagemCustoGerais"
[spinners]="false"
[readonly]="true"
[round]="false"
[decimals]="2"
>
</kendo-numerictextbox>

 

3 Answers, 1 is accepted

Sort by
0
Hetali
Telerik team
answered on 15 Sep 2020, 06:54 PM

Hello Lucas,

Thank you for the snippet.

Upon replicating the issue observed by you, the decimal value was not rounded as seen in this StackBlitz example. The NumericTextBox component does not have the round property.

The built-in format 'p' multiplies the number by 100 to show the percentage value. To prevent the number from multiplying, use the '#' specifier as described in this GitHub page to define the custom format. For example:

<kendo-numerictextbox
  [format]="'##.## \\\\%'"
  [(ngModel)]="porcentagemCustoGerais"
  [spinners]="false"
  [readonly]="true"
>
</kendo-numerictextbox>
In this StackBlitz example, the value 2.74 is not rounded off and is shown as a percentage value. However, if you continue to face the issue, could you please update the example such that it replicates the behavior observed by you? I will then investigate.

Please let me know if this information helps or if I can further assist you.

Regards,
Hetali
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Lucas
Top achievements
Rank 1
answered on 18 Sep 2020, 08:57 PM

HI Hetali,

Thank you for the reply.

I think I was not clear about my question, so sorry for that. My problem is that when i put a number like 0.0274 it would me show 3% instead of 2.74%, I saw the github page and i think it's possible using 

formatNumber(0.5678, "p2", "de")

 

I believe what i need is the "de" parameter, but i don't know how to implemet it on the kendo-numerictextbox, is this the equivalent of 

[decimals]="decimals"

 

or is something else?

 

Regards,

Lucas

0
Hetali
Telerik team
answered on 21 Sep 2020, 08:55 PM

Hello Lucas,

Thank you for the additional details.

By setting the format of the Kendo UI NumericTextBox using the built-in 'p' specifier to 'p2', the value 0.0274 will be shown as 2.74%. The number after 'p' is used to define the decimal places (2 in your case). The format 'p' will show the value as 3% as seen in this updated StackBlitz example.

The 'de' in the following syntax represents the language code for German. 

formatNumber(0.5678, "p2", "de");

I hope this information helps. Let me know if you have any further questions pertaining to this case.

Regards,
Hetali
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Tags
NumericTextBox
Asked by
Lucas
Top achievements
Rank 1
Answers by
Hetali
Telerik team
Lucas
Top achievements
Rank 1
Share this question
or