Skip to content

Instantly share code, notes, and snippets.

@melnikovdv
Created March 9, 2016 14:08
Show Gist options
  • Save melnikovdv/da02b009c63a46a9d246 to your computer and use it in GitHub Desktop.
Save melnikovdv/da02b009c63a46a9d246 to your computer and use it in GitHub Desktop.
Склонятор числительных
public static String plural(long n, String form1, String form2, String form3) {
n = Math.abs(n);
int plural = (n % 10 == 1 && n % 100 != 11 ? 0 : (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2));
switch (plural) {
case 1:
return form2;
case 2:
return form3;
default:
return form1;
}
}
// text = plural(count, "минута", "минуты", "минут");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment