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
24 lines (20 loc) · 724 Bytes
/
Formatter.java
File metadata and controls
24 lines (20 loc) · 724 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
public class Formatter {
public static String formatDoubleToString(double inputNumber) {
int roundedNumber = (int) Math.floor(inputNumber);
int preLastDigit = roundedNumber % 100 / 10;
int lastDigit = roundedNumber % 10;
String rublesValue;
if (preLastDigit == 1) {
rublesValue = "рублей";
} else {
if (lastDigit == 1) {
rublesValue = "рубль";
} else if (lastDigit >= 2 && lastDigit <= 4) {
rublesValue = "рубля";
} else {
rublesValue = "рублей";
}
}
return String.format("%.2f", inputNumber) + " " + rublesValue;
}
}