Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

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

Open
DevilReina wants to merge 3 commits intomain from
dev
Open

Спринт 2. Проектная работа No1 #1
DevilReina wants to merge 3 commits intomain from
dev

Conversation

@DevilReina
Copy link
Owner

@DevilReina DevilReina commented Mar 12, 2023

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

@ilshat-abdulin ilshat-abdulin Mar 13, 2023

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

@ilshat-abdulin ilshat-abdulin Mar 14, 2023

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

@ilshat-abdulin ilshat-abdulin Mar 14, 2023

Choose a reason for hiding this comment

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

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

DevilReina reacted with rocket emoji
Copy link
Owner Author

@DevilReina DevilReina Mar 14, 2023

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

Reviewers

1 more reviewer

@ilshat-abdulin ilshat-abdulin ilshat-abdulin left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /