Skip to content

Спринт 2. Проектная работа №1 - #1

Open
DevilReina wants to merge 3 commits into
mainfrom
dev
Open

DevilReina wants to merge 3 commits into
mainfrom
dev

Conversation

@DevilReina

Copy link
Copy Markdown
Owner

No description provided.

Comment on lines +2 to +15
String numFormat (double num) {
double lastNumber = num % 100;
int ruble =(int) Math.floor(lastNumber);
switch (ruble) {
case 1:
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠ Если будет передано функции 24, то на выходе получим 24,00 рублей.
Снимок экрана 2023-03-13 201440

Чтобы рассчитать правильное окончание, нужно учесть также остаток от деления на 10. Остаток от 100 стоит проверять в диапазоне чисел от 11 до 19 включительно

Также рекомендую сначала округлить число
double lastNumber = (int) Math.floor(num);
А затем получить остаток
lastNumber % 100; и lastNumber % 10;

public class Formatter {
String numFormat (double num) {
double lastNumber = num % 100;
double lastNumber = (int) Math.floor(num);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно тип сделать int

Comment on lines +5 to +8
if (lastNumber % 100 >= 11 && lastNumber % 100 <= 14) {
return " рублей";
}
switch (ruble % 10) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все правильно. Молодец! 👍

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants