Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

43
LINES

< > BotCompany Repo | #1032117 // n2UnlessZero - empty string when number is zero

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3135L/17K).

static S n2UnlessZero(long l) { ret l == 0 ? "" : formatWithThousands(l); }
static S n2UnlessZero(Collection l) { ret n2UnlessZero(l(l)); }
static S n2UnlessZero(Map map) { ret n2UnlessZero(l(map)); }

sS n2UnlessZero(double l, S singular) {
  ret n2UnlessZero(l, singular, singular + "s");
}

sS n2UnlessZero(double l, S singular, S plural) {
  if (fraction(l) == 0)
    ret n2UnlessZero((long) l, singular, plural);
  else
    ret l + " " + plural;
}

static S n2UnlessZero(long l, S singular, S plural) {
  ret n_fancy2UnlessZero(l, singular, plural);
}

static S n2UnlessZero(long l, S singular) {
  ret n_fancy2UnlessZero(l, singular, singular + "s");
}

static S n2UnlessZero(Collection l, S singular) {
  ret n2UnlessZero(l(l), singular);
}

static S n2UnlessZero(Collection l, S singular, S plural) {
  ret n_fancy2UnlessZero(l, singular, plural);
}

static S n2UnlessZero(Map m, S singular, S plural) {
  ret n_fancy2UnlessZero(m, singular, plural);
}

static S n2UnlessZero(Map m, S singular) {
  ret n2UnlessZero(l(m), singular);
}

static S n2UnlessZero(long[] a, S singular) { ret n2UnlessZero(l(a), singular); }

static S n2UnlessZero(O[] a, S singular) { ret n2UnlessZero(l(a), singular); }
static S n2UnlessZero(O[] a, S singular, S plural) { ret n_fancy2UnlessZero(a, singular, plural); }

Author comment

Began life as a copy of #1012632

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032117
Snippet name: n2UnlessZero - empty string when number is zero
Eternal ID of this version: #1032117/3
Text MD5: 5928c6924b654743c9b0c5aa8f574099
Transpilation MD5: d88a3f3765e8fb8c2953e01ee4805a72
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-14 01:46:31
Source code size: 1347 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 74 / 112
Version history: 2 change(s)
Referenced in: [show references]