forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.java
More file actions
32 lines (30 loc) · 1.15 KB
/
Utils.java
File metadata and controls
32 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Utils {
// контроль строки, является ли она целым числом
public static boolean isInt(String aStr) {
try {
Integer.parseInt(aStr);
return true;
} catch (NumberFormatException e) {
return false;
}
}
// получение строки дробного числа с разделителем . и двумя знаками после запятой
public static String toStringCustomFormat(double aDoubleNumber) {
return String.format("%.2f", aDoubleNumber).replace(',', '.');
}
// получить написание "рубль" с правильным окончанием
public static String getRoubleSuffix(double aSumRouble) {
int mod = (int) (Math.floor(aSumRouble) % 100);
if (mod > 10 && mod < 15) {
return "рублей";
} else {
switch (mod % 10) {
case 1: return "рубль";
case 2:
case 3:
case 4: return "рубля";
default: return "рублей";
}
}
}
}