LimeReport Forum
General Category | Основное => Discussion | Обсуждение => Topic started by: Paul Traut on December 15, 2017, 12:00:12 pm
-
Hello,
I would like to use a "counter" within a text field like
1st
2nd
3rd
4th
...
21st
22nd
23rd
24th
...
and so on.
Is there a possibility to do this in a way, that makes sure that the 2718th entry is also formatted correct?
Paul
-
PS.: How can I format a text within LimeReport to get something like this "HelloHello "???
Paul
-
Hi
You can write something like this in the init script
function formatNumber(number){
var lastNumber = number.toString().charAt(number.toString().length-1);
switch(lastNumber){
case "1":
result = "<sup>st</sup>"
break;
case "2":
result = "<sup>nd</sup>"
break;
......
}
return number.toString()+result;
}
And use it in a TextItem with AlloHTML
$S{formatNumber(12)}
-
Ok, thanks.
But this means, I have to write within the script a case for every single number that I could expect ???
-
Hello Alex,
this code doesent work right, I get
1<sup>st</sup>
2<sup>nd</sup>
...
as a result and not
1st
2nd
...
-
Case should process only the last digit in the number.
Do you turn on AllowHTML at TextItem?
-
Oh
I have over read this important information, now it works ;D Thanks.
Can I also use the MOD operator within the script, than it would be easier to write a script for an unknown amount of lines
:)
-
Hi
You can write something like this in the init script
function formatNumber(number){
var lastNumber = number.toString().charAt(number.toString().length-1);
switch(lastNumber){
case "1":
result = "<sup>st</sup>"
break;
case "2":
result = "<sup>nd</sup>"
break;
......
}
return number.toString()+result;
}
А куда этот код запихивать? Туплю немного)
-
Hello Fynjy,
unfortunately, I can not read Russian :(
-
Paul, the question by Fynjy about the init script location in LMDesigner...
Fynjy: смотри файл, там стрелкой указано, где инит скрипт располагать
-
Paul,
Can I also use the MOD operator within the script, than it would be easier to write a script for an unknown amount of lines
Limereport uses javascript. In javascrip Modulus (%) operator returns only the remainder.
-
Paul, the question by Fynjy about the init script location in LMDesigner...
Fynjy: смотри файл, там стрелкой указано, где инит скрипт располагать
Ok, Thanks
Paul,
Can I also use the MOD operator within the script, than it would be easier to write a script for an unknown amount of lines
Limereport uses javascript. In javascrip Modulus (%) operator returns only the remainder.
Thanks, will use this
-
Ok,
here is my solution. Maybe someone is searching for the same in the future
:)
function formatNumber(number)
{
var modNumber = number % 10;
switch(modNumber)
{
case 1 :
{
tensDigit = number.toString().charAt(number.toString().length-2);
switch(tensDigit)
{
case "1":
result = "<sup>th</sup>"
break;
default:
result = "<sup>st</sup>"
break;
}
}
break;
case 2 :
result = "<sup>nd</sup>"
break;
case 3 :
result = "<sup>rd</sup>"
break;
default:
result = "<sup>th</sup>"
break;
}
return number.toString()+result;
}