Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: numberFormat  (Read 1498 times)

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
numberFormat
« 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

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 992
    • View Profile
Re: numberFormat
« Reply #1 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)
}

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: numberFormat
« Reply #2 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