public class Formatter { public String formatRub(double price) { double roundedPrice = Math.floor(price) % 10; double roundedPrice2 = Math.floor(price) % 100; String wording; if (roundedPrice2 == 11 || roundedPrice2 == 12 || roundedPrice2 == 13 || roundedPrice2 == 14) { wording = roundPrice(price) + " ÑÑблей.\n"; } else if (roundedPrice == 1) { wording = roundPrice(price) + " ÑÑблÑ.\n"; } else if (roundedPrice < 5 && roundedPrice > 1) { wording = roundPrice(price) + " ÑÑблÑ.\n"; } else { wording = roundPrice(price) + " ÑÑблей.\n"; } return wording; } private String roundPrice(double price) { return String.format("%.2f", price); } }