Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Ruby

Idiom #358 Format a value in unit notation

Create the end-user text, s, specifying the value a, in units of x.

For example, "0 files", "1 file", or "1,000 files".

s = "#{a} #{x}#{a == 1 ? "" : "s"}"
import java.text.ChoiceFormat;
String s = "0#files|1#file|1<files";
s = new ChoiceFormat(s).format(a);
s = "%,d %s".formatted(a, s);

New implementation...
< >
reilas