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

conditional formatting of number decimal part

2 Answers 528 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Veteran
Ron asked on 21 Jun 2019, 03:24 PM

Hello,
Our app displays many numbers and we often use the kendo.toString function according to https://docs.telerik.com/kendo-ui/globalization/intl/numberformatting 
In some places we use it with the format ##,# (to display integers) and in others we use ##,#.00 to always print the decimal part.


Here are two examples:
kendo.toString(12345.10, "##,#”) >>”12,345"
kendo.toString(12345.10, "##,#.00”) >> "12,345.10"
In certain area we wish to be able and present integers as integers, and without the decimal part, and present floats with two decimal parts.
Clearly we cannot use any of the suggested format. Using ##,# only gives integers and ##,#.00 will turn 10 into 10.00 while we wish to keep it as 10


We also cannot use ##,#.## because we cannot allow only 1 decimal digit. The result of kendo.toString(10.1, "##,#.##”) is “10.1” but we must have it as “10.10” because we need either 0 decimal figures or 2.


Is there a format that can answer this need?

 

Thanks,

Ron.


2 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 25 Jun 2019, 01:23 PM
Hello Ron,

I'm afraid that there is not format that could cover these cases at once. What I can suggest you is to check (if statement) the type of the number and depending on the case - use the needed format. e.g.:

(x % 1 !== 0) ? kendo.toString(x, "#.00") : kendo.toString(x, "#")

Hope this would help.

Regards,
Nencho
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
Ron
Top achievements
Rank 1
Veteran
answered on 25 Jun 2019, 08:46 PM
Thanks! Much appreciated.
Tags
General Discussions
Asked by
Ron
Top achievements
Rank 1
Veteran
Answers by
Nencho
Telerik team
Ron
Top achievements
Rank 1
Veteran
Share this question
or