forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatter.java
More file actions
27 lines (24 loc) · 794 Bytes
/
Formatter.java
File metadata and controls
27 lines (24 loc) · 794 Bytes
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
class Formatter {
double rubles;
public static String typeMoneyRub(double rubles) {
double rublesFloor = Math.floor(rubles);
String rub[] = new String[3];
rub[0] = "рубль";
rub[1] = "рубля";
rub[2] = "рублей";
String rublesOut;
int rublesFloorInt = (int) rublesFloor % 100; // Преобразуем в int для switch/case
if(rublesFloorInt > 19) {
rublesFloorInt = rublesFloorInt % 10;
}
rublesOut = switch (rublesFloorInt) {
case 1 -> rub[0];
case 2, 3, 4 -> rub[1];
default -> rub[2];
};
return rublesOut;
}
public static String moneyCut(double rubles) {
return String.format("%.2f", rubles);
}
}