g | x | w | all
Bytes Lang Time Link
007Uiua240729T163743ZErikDaPa
005UiuaSBCS240729T115559ZEurope20
011ARBLE230809T045224ZATaco
003Nekomata230809T015539Zalephalp
003Thunno 2230808T173744ZThe Thon
003Vyxal210604T090412Zemanresu
109Rockstar200914T164622ZShaggy
010Perl 5 p200914T173312ZXcali
006Keg191206T104624Zlyxal
008TI BASIC191211T183059ZTiKevin8
005Pyth191210T192705Zfrank
015Java JDK191208T143051ZOlivier
nanPerl 5191209T062135ZNathan M
017JavaScript Node.js191206T084259Ztsh
064Intcode day 5191208T064410ZDoorknob
015JavaScript191208T123833ZAndrew T
099Java191208T010032ZMALware
049Brainfuck191207T220009ZExalted
019Javascript ES6191207T202439ZG0BLiN
025C++ gcc191207T001524ZNoodle9
007Wolfram Language Mathematica191207T123347ZGreg Mar
004W191206T215317Zlyxal
002Japt191206T101334ZShaggy
006GolfScript191206T213556ZPseudo N
010Charcoal191206T211644ZNeil
025C gcc191206T133241ZBenguini
004MATL191206T113748ZLuis Men
008K oK191206T193817ZGalen Iv
061SimpleTemplate191206T190523ZIsmael M
030Prolog SWI + CLPFD191206T174647Zuser4180
007x86 Machine Code191206T165432Z640KB
020R191206T164907ZRobert S
010Runic Enchantments191206T164049ZDraco18s
003MathGolf191206T163214ZKevin Cr
008APL+WIN191206T143652ZGraham
008Pyth191206T104247ZElPedro
006J191206T085254ZGalen Iv
031Red191206T090021ZGalen Iv
013Ruby191206T110740Zgame0ver
028Retina 0.8.2191206T104343ZNeil
014Haskell191206T103006Zxnor
017Python191206T101546Zxnor
018Python 2191206T085316ZChas Bro
003Jelly191206T085604ZNick Ken
017Octave191206T084652Zflawr
022JavaScript V8191206T083845Zflawr

Uiua, 7 bytes

×⟜(⌈÷):

Try it online!

Explanation:

 ⟜(⌈÷): -> ceil(a/b)
×       -> multipled by b

UiuaSBCS, 5 bytes

×⊙⌈⟜÷

Try it online!

Takes two stack values, second argument on top.

Explanation

×⊙⌈⟜÷
   ⟜÷ divide while keeping the top argument in place
 ⊙⌈   round the bottom value up
×     multiply

ARBLE, 11 bytes

ceil(a/b)*b

Try it online!

Nekomata, 3 bytes

/K*

Attempt This Online!

\div, \ceil, \mul.

Thunno 2, 3 bytes

/ṃ×

Try it online!

Explanation

/ṃ×  # Implicit input
/    # Divide
 ṃ   # Ceil
  ×  # Multiply
     # Implicit output

Vyxal, 3 bytes

/⌈*

Try it Online!

Rockstar, 115 109 bytes

F takes X
let M be X/D
turn up M
return M is X/D

listen to N
listen to D
until F taking N
let N be--1

say N

Try it here (Code will need to be pasted in, input on individual lines)

Perl 5 -p, 10 bytes

$_+=-$_%<>

Try it online!

Keg, -hr, 17 9 6 bytes

¿±¿%¿+

A port of my W answer which is a port of Xnor's python answer

Answer History

9 bytes -rR

&¿{:⑻$%|⑹

Explained

&¿{:⑻$%|⑹
&           #Store the implicit input (the number to round) in the register
 ¿          #Take the number to 'round by'
  {         #While:
   :⑻      #Duplicate the 'round by' and push the register without emptying it
     $%  #Swap the two and perform modulus, checking the result against 0
       |⑹  #    Increment the register

Answer History

17 bytes

&¿{:&:&$%|&1+&}&

Try it online!

TI BASIC, 8 bytes

-Bint(-A/B

"-" is the negative symbol here, distinct from the minus symbol on the calculator. TI BASIC doesn't have a token for a rounding up operation, we have to pick between iPart( and int( or take another route with fPart( or remainder( on OS 2.53+. int( rounds -2.5 down to -3 where iPart( would return -2, so we can use int( with negation to turn rounding down into rounding up.

Disp is implicit because the result is the final line, and the function can be a full program easily by adding Prompt A,B.

Pyth, 5 bytes

+%_QE

Try it online!

Port of @xnor's answer

How it works

+%_QE
+    (Q)- The sum of the implicit first input and...
  _Q    - The negative of the first input...
 %  E   - Modulo the second input

Java (JDK), 15 bytes

b->a->--a+b-a%b

Try it online!

Perl 5, (111 bytes with footer) 52 bytes

sub f{($a,$b)=@_;$c=$b;$c++until!($c%$b)&&$c>=$a;$c}

Try it online!

Takes a and b as arguments to a subroutine named f and increases $c until it is both a multiple of $b and greater than or equal to $a. Then returns $c (the last value evaluated in a subroutine is the return value).

JavaScript (Node.js), 17 bytes

a=>b=>a+(b-a%b)%b

Try it online!

Intcode (day 5), 70 66 64 bytes

3,0,3,2,102,-1,2,4,1,0,4,0,1,1,8,1,7,9,0,5,5,5,14,2,1,2,0,4,0,99

Try it online!

Intcode is a programming language invented for Advent of Code 2019. It was first introduced on day 2, then further expanded upon on day 5, which is the version used here.

Since on PPCG, languages are defined by their interpreters, I am using the interpreter that I wrote for my day 5 solution (which was written before this challenge).

Explanation:

3,0,          store first input in cell 0
3,2,          store second input in cell 2
              (cell 1 is a counter, because it's already initialized to zero)
102,-1,2,4,   negate the second input and store in cell 4

              (begin loop)
1,0,4,0,      subtract the second input from the first input
1,1,8,1,      increment the counter (by adding cell 8)
7,9,0,5,      if the first input is greater than zero (cell 9)...
5,5,14,       ... jump to the beginning of the loop (reusing the cell 8 reference)

2,1,2,0,      multiply the counter by the second input
4,0,99        output and quit

JavaScript, 15 bytes

a=>b=>--a+b-a%b

More expressively, the answer is a => b => a + b-((a-1)%b) - 1, but by decrementing a we can handle both the "subtract one" steps at once, saving a couple of bytes. Then we just get lucky with operator presidencies.

Java, 99 bytes

static int r(int a,int b){int t=a%b<1||b%a<1?a:r(a+1,b);return t;}

Brainfuck, 52 49 bytes

Thanks to Jo King for finding a bug, helping fix it with some extra golfing.

,>>,<<[>+>->+<[>]>[<+>-]<<[<]>-]>>>[<[-<+>]>,]<<.

Input and output is in character codes.

Try it online!

Explanation

,>>,<<                     [>a, 0,     b,   0]
[>+>->+<[>]>[<+>-]<<[<]>-] [>0, a, b-a%b, a%b]
>>>[<[-<+>]>,]             If a%b is nonzero, add b-a%b to a, and clear a%b
<<.                        Output a+(b-a%b)

Modulus algorithm is straight from the esolang list of brainfuck algorithms.

Javascript (ES6), 19 bytes

a=>b=>a%b?a-a%b+b:a

Naive attempt, pretty sure this can be golfed further.

C++ (gcc), 43 41 40 36 25 bytes

#define f(a,b)(b-a%b)%b+a

Try it online!

Saved 4 bytes thanks to @Neil!!!

Saved 11 bytes thanks to @AZTECCO!!!

Wolfram Language (Mathematica), 7 bytes

Ceiling

Just pointing out that Mathematica's builtin, which is most commonly called with one argument, actually does exactly the desired operation when called with two arguments.

W, 7 4 bytes

_bm+

-3 bytes thanks to @A

Answer History

0a-bma+

Yet another port of xnor's Python answer.

Japt, 2 bytes

cV

Try it

cV     :Implicit input of integers U & V
cV     :Round U up to the nearest multiple of V

With input as an array:

rc

Try it

rc     :Implicit input of array
r      :Reduce by
 c     :Rounding the first element up to the nearest multiple of the second

Less Trivial!, 6 bytes

_vV}aU

Try it

_vV}aU     :Implicit input of integers U & V
_          :Function taking an integer Z as input
 vV        :  Is Z divisible by V?
   }       :End function
    aU     :Starting from U, return the first integer that returns true when passed through that function
ôV ævV

Try it

ôV ævV     :Implicit input of integers U & V
ôV         :Range [U,U+V]
   æ       :Get first element
    vV     :  Divisible by V

GolfScript, 6 bytes

.~)@%+

Try it online!

Function which consumes A and B from the stack, assuming B is below A.

Explanation:

           #Example input: A = 12, B = 5          stack is  5  12
.~)        #Duplicate A and negate the duplicate  stack is  5  12 -12
   @       #Pull 3rd from top to top              stack is 12 -12   5
    %      #Second to top mod top                 stack is 12 3
     +     #Add remaining values                  stack is 15

Charcoal, 10 bytes

≔±NθI×θ÷Nθ

Try it online! Link is to verbose version of code. Takes \$ b \$ first and \$ a \$ second. Explanation:

≔±Nθ

Input \$ b \$, negate it, and save the result.

I×θ÷Nθ

Input \$ a \$ and compute \$ -b \lfloor \frac a {-b} \rfloor \$, then cast to string for implicit print.

C (gcc), 47 31 25 bytes

f(a,b){a=a%b?f(++a,b):a;}

Try it online!

-16 bytes thanks to A̲̲ (forgot that return types and parameters would default to int if not defined, whoops!)

-6 thanks to AZTECCO for using a ternary and making the function recursive

MATL, 4 bytes

:ien

Try it online!

Explanation

Consider inputs 12, 5.

     % Implicit input
:    % Range
     % STACK: [1 2 3 4 5 6 7 8 9 10 11 12]
i    % Input
     % STACK: [1 2 3 4 5 6 7 8 9 10 11 12], 5
e    % Reshape as a matrix with that number of rows, padding with zeros
     % STACK: [1  6 11;
               2  7 12;
               3  8  0;
               4  9  0;
               5 10  0]
n    % Number of elements
     % STACK: 15
     % Implicit display

K (oK), 8 bytes

{x+y!-x}

Try it online!

Another port of xnor's Python answer.

SimpleTemplate, 61 bytes

This was quite fun! Sadly, I had to do the dumb way :(

{@fn F A,B}{@whileA is notmultipleB}{@incA}{@/}{@returnA}{@/}

Creates a function that iterates until it finds a number that's multiple of the 2nd number.

This was actually way smaller than doing it without a function.


Ungolfed:

{@fn F numberA, numberB}
    {@while numberA is not multiple of numberB}
        {@inc by 1 numberA}
    {@/}
    {@return numberA}
{@/}

Should be mostly straightforward.

You can see it running on https://ideone.com/MR7t1E (golfed version only).

Prolog (SWI) + CLPFD, 30 bytes

f(R,X,Y):-R#=_*Y,R-Y#<X,R#>=X.

Try it online!

f(R,X,Y)

f is a predicate taking in a variable R, and two integers X and Y.

The CLPFD constraints are expressed using the #-prefixed operators. , means and, so f is true iff all these constraints are satisfied, i.e.,

1) R#=_*Y R is a multiple of Y , and

2) R-Y#<X R-Y < X , and

3) R#>=X R >= X .

x86 Machine Code, 7 bytes

Since x86 integer division instructions do only floor rounding, this uses the formula: f(a,b) = floor((a+b-1)/b)*b to accomplish ceiling rounding.

02 C3   ADD  AL, BL     ; a = a + b
48      DEC  AX         ; a = a - 1
F6 F3   DIV  BL         ; a = a / b
F6 E3   MUL  BL         ; a = a * b

Input is in AL and BL, output is AL.

Testing

Here is output from a test program for PC DOS that takes interactive input.

enter image description here

Download and test ROUNDMY.COM.

R, 20 bytes

function(a,b)a+-a%%b

Try it online!

Runic Enchantments, 10 bytes

ii:},'cA*@

Try it online!

ii            Read a, read b
  :}          Dup b, rotate to bottom of stack
    ,         Divide
     'cA      Ceiling
        *     Multiply
         @    Output and terminate

MathGolf, 3 bytes

/ü*

Similar approach as other answers: \$\lceil\frac{a}{b}\rceil b\$.
I/O as floats with .0, with the inputs in the order a b.

Try it online.

Explanation:

/    # Divide the second (implicit) input by the first (implicit) input
     #  i.e. 3.0 5.0 → 1.666...
 ü   # Ceil it
     #  → 2
  *  # Multiply it by the first (implicit) input
     #  → 6.0
     # (output the entire stack joined together implicitly as result)

APL+WIN, 8 bytes

Prompts for b followed by a:

b×⌈⎕÷b←⎕

Try it online! Courtesy of Dyalog Classic

Pyth, 8 bytes

AQ+G%_GH

Try it online!

Simple port of the Python answer from xnor so please give that answer an upvote.

Debugged:

==================================================
assign('Q',eval_input())
assign('[G,H]',Q)
imp_print(plus(G,mod(neg(G),H)))
==================================================

J, 6 bytes

]*>.@%

Try it online!

]         the right argument
 *        multiplied by
  >.@     the ceiling of
     %    the left argument dividided by the right one

If we can swap the order of the aruments:

J, 5 bytes

]+[|-

Try it online!

Red, 31 bytes

func[a b][round/to/ceiling a b]

Try it online!

Just a built-in round with refinements to, which scales the first argument according to the second, and ceiling, which indicates the direction.

Red, 25 bytes

func[a b][0 - a // b + a]

Try it online!

A port of xnor's Python answer. Don't forget to upvote his answer!

Ruby, 13 bytes

->a,b{-a%b+a}

Try it online!

Retina 0.8.2, 28 bytes

\d+
$*
r`1+(\2*) (1+)
$1$2
1

Try it online! Link includes test cases. Explanation:

\d+
$*

Convert the inputs to unary.

r`

Process this stage from right-to-left, so that \2 gets to match \$ b \$ first, allowing us to refer to it when matching within \$ a \$.

1+(\2*) (1+)

Match \$ b \$ in \2, then as many copies of \$ b \$ as we can, without completely exhausting \$ a \$. \1 thus matches \$ b \lfloor \frac {a - 1} b \rfloor = b \lceil \frac {a - b} b \rceil \$

$1$2

Add that to \$ b \$ to give \$ b \lceil \frac a b \rceil \$.

1

Convert to decimal.

Haskell, 14 bytes

a%b=a+mod(-a)b

Try it online!

Python, 17 bytes

lambda a,b:a+-a%b

Try it online!

Since this doesn't use division, it works for both Python 2 and 3. Note that we can't cut out the + sign because a-a%b does a-(a%b), whereas we want to do(-a)%b and add that to a. We could also write it as -a%b+a.

Python 2, 23 20 18 bytes

lambda a,b:-a/b*-b

Try it online!

2 bytes thanks to tsh

Jelly, 3 bytes

÷Ċ×

Try it online!

Simply divide, ceiling, multiply.

Octave, 17 bytes

Same method as this JS answer:

@(a,b)ceil(a/b)*b

Try it online!

JavaScript (V8), 22 bytes

This is the function \$(a,b) \mapsto \left\lceil \frac{a}{b} \right\rceil b\$.

a=>b=>Math.ceil(a/b)*b

Try it online!