LimeReport Forum

General Category | Основное => Discussion | Обсуждение => Topic started by: Paul Traut on October 23, 2018, 12:11:20 PM

Title: numberFormat
Post by: Paul Traut on October 23, 2018, 12:11:20 PM
Hello,

depending on the number I would like to have something like
1 -> 001
2 -> 002
.
.
10-> 010
11-> 011
.
.
100->100

and so on.

Howe can I set this within the numberFormat function and is there a Wiki where all possibilities are described?

Thanks Paul
Title: Re: numberFormat
Post by: Arin Alex on October 23, 2018, 12:55:22 PM
Hi!
You can use this trick
1. Put into the initscript next helper:
Code: [Select]
Number.prototype.pad = function(size) {
  var s = String(this);
  while (s.length < (size || 2)) {s = "0" + s;}
  return s;
}
2. use it in TextItem like this:
Code: [Select]
$S{
  (1).pad(3)
}
Title: Re: numberFormat
Post by: Paul Traut on October 23, 2018, 04:55:49 PM
Hi,

thanks for your answer.

My solution now is:
Code: [Select]
$S{
if ( $S{$D{test.COUNT(*)}+1} <10)
"00"+$S{$D{test.COUNT(*)}+1};
else if ( $S{$D{test.COUNT(*)}+1} <100)
"0"+$S{$D{test.COUNT(*)}+1};
else
$S{$D{test.COUNT(*)}+1}
}

and this works fine for me.
I only thought that there is something with the "numberFormat" function.

Paul