programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

Commercial Rounds

Greenhorn
Posts: 1
Hi This semester I started learning Informatics as a subject and I am an absolute beginner. We have to do homework every week and this time I couldn't figure out, how eactly the task should be solved.

And the task is we have to round some numbers. If the number ist for example a double 3.14 or 0.49 - we have to round it down to an int 3 and an int 0, and if we have a number like 10.5 it should be rounded up to int 11.

We were told NOT to use the Math.round method for this task and were also given the hint, that the task could be done in only one line of code.

Exactly the creating if the one line of code is the thing I cannot figure out. Does someone of you guys know an efficient solution to this problem? How can I convert both types of doubles in one and the same command?

Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
Think about it for a moment. If you simply truncate the number as is to an integer (there's a method for that), the .5 and over numbers would not end up with the right value. So.... is there something you could do to the number that would cause the truncation to give the right value?

Henry Wong
author
Sheriff
Posts: 23295
125