Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Save 6 bytes thanks to the awesome comments of MarcMush!
x->x-x%1+sign(rem>x+sign(x,1)x%=1)-x
Try it online!Try it online!
An alternative with the same number of22 bytes
x->sign(x)*ceilceil(abs(x))
x->x-x%1+sign(rem(x,1))
Try it online!
An alternative with the same number of bytes
x->sign(x)*ceil(abs(x))
x->x+sign(x%=1)-x
An alternative with 22 bytes
x->sign(x)ceil(abs(x))