dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Aug 5, 2019

Divide Two Positive Integers and Round Up

In Java, we can divide two positive integers and round up as follows:

int result = (x + y - 1) / y

Example: (4/3 = 1.33 and we want 2):

long result = (4 + 3 - 1) / 3; // 2
Octavia Anghel
 
Thanks for your registration, follow us on our social networks to keep up-to-date