g | x | w | all
Bytes Lang Time Link
020Raku Perl 6 rakudo250417T165241Zxrs
023Juby250408T153541ZJordan
031AWK250408T151342Zxrs
020Risky210720T222747Zxigoi
004Vyxal r210501T054812ZAaroneou
017Julia 1.0210501T005919ZTanj
048PowerShell Core210429T230109ZJulian
037PowerShell Core210430T051915Zmazzy
164MMIX210429T202647ZNoLonger
005APLDyalog Unicode210212T070902ZRazetime
005Husk201018T160838ZLegionMa
021JavaScript node.js190905T174817ZSagittar
016Runic Enchantments190903T212459ZDraco18s
024C# Visual C# Compiler190904T141601Zhessam h
039C190904T030715Zgirobuz
035Perl 5 pF/\./190904T023144ZXcali
030PHP190904T114026ZNight2
1312sed190904T233703ZRay
036Vim190903T212729ZDJMcMayh
015APL Dyalog Unicode190904T153522ZJ. Sall&
005MathGolf190904T140114Zmaxb
035Zsh190904T122653Zroblogic
057Factor190904T132444ZGalen Iv
016Scala190904T091511ZSoapy
018Java JDK190904T113235ZOlivier
018Perl 6190903T235120Znwellnho
018Wolfram Language Mathematica190904T080900Zatt
020JavaScript ES6190903T211348ZArnauld
046Red190904T065901ZGalen Iv
004Jelly190903T211007Zcaird co
023Python 3190903T214527ZJitse
006Japt190904T065240ZShaggy
00605AB1E190904T062447ZKevin Cr
006J190904T032208ZJonah
013Excel190904T012715Znwellnho
043Java OpenJDK 8190903T231954ZX1M4L
019Perl 6190903T232826ZJo King
038Retina 0.8.2190903T222601ZNeil
007Brachylog190903T222144ZUnrelate
004Jelly190903T215435ZJonathan
032R190903T213152ZPuninten
006Stax190903T212806Zrecursiv

Raku (Perl 6) (rakudo), 20 bytes

{.sign*.abs.ceiling}

Attempt This Online!

{.sign    # returns 1/-1
*         # multiply
.abs      # absolute value
.ceiling} # round up

J-uby, 23 bytes

:*%[:abs|:ceil,~:<=>&0]

Explanation

:* % [ :abs | :ceil, ~:<=> & 0 ]
:* % [             ,           ]  # Product of...
       :abs | :ceil               #   ceiling of absolute value of input and
                      ~:<=> & 0   #   signum of input

Attempt This Online!

AWK, 56 31 bytes

{$2&&$1+=$1>0?1:-1}1,$0=int($1)

Attempt This Online!

{int(a=$0)!=a&&substr(a,length)&&a+=a>0?1:-1}1,$0=int(a)

Attempt This Online!

{int(a=$0)!=a       # if it's decimal
&&substr(a,length)  # and not zero
&&a+=a>0?1:-1}      # then round away 
1,                  # force output for zero
$0=int(a)           # set output to integer

Risky, 20 bytes

_?{0-1?{0/_?{1+_0+0+1?{0+_0+0+_0+0+_0+0

Try it online!

Takes a pair representing a rational number.

Vyxal r, 5 4 bytes

Built-ins I previously didn't know existed FTW!

ȧ⌈∆±

Try it Online!

Explanation:

      # Implicit input
ȧ     # Absolute value
 ⌈    # Ceiling
  ∆±  # Change to the sign of input
      # Implicit output

Julia 1.0, 17 bytes

Save 6 bytes thanks to the awesome comments of MarcMush!

x->x+sign(x%=1)-x

Try it online!

An alternative with 22 bytes

x->sign(x)ceil(abs(x))

Try it online!

PowerShell Core, 54 48 bytes

$a,$u=$args-split'\.'
(1,-1)[2*!+$u+($a-lt0)]+$a

Try it online!

Thanks @mazzy for the improved golfing !

Original implementation

$a,$u="$args"|% s*t '.'
(((1,-1)[$a-lt0]+$a),$a)[!+$u]

Try it online!

Explanations

$a,$u="$args"|% s*t '.'        # splits the input as a string using '.'
                        [!+$u] # if there are no decimals
(                   ,$a)       # return the int part as is
 ((1,-1)[$a-lt0]+$a)           # return the int part + or - one depending of the sign of the input

PowerShell Core, 45 38 37 bytes

[int]("$args"-replace'\.0*[^0]','.9')

Try it online!

MMIX, 16 bytes (4 instrs)

40000002 17000200 17000300 F8010000

Disassembly / Explanation

rfz BN   $0,0F              // if negative, skip next instruction
    FINT $0,ROUND_UP,$0     // round to integer towards +inf
0H  FINT $0,ROUND_DOWN,$0   // round to -inf, no effect if already rounded
    POP  1,0                // return

APL(Dyalog Unicode), 5 bytes SBCS

××⌈∘|

Try it on APLgolf!

A train submission which takes a number on the right. Uses recursive's idea.

Husk, 5 bytes

*±¹⌈a

Try it online! Just takes the sign of the input times the ceiling of its absolute value.

JavaScript (node.js), 30 23 21 bytes

s=>~~s+Math.sign(s%1)

Inspired by the C# answer.

Thanks to @Value Ink and @Gust van de Wal for -7 bytes!

Thanks again, @Gust van de Wal for another -2 bytes!

Runic Enchantments, 18 16 bytes

1µ-i:'-A{*+'.A@

Try it online!

"Adds" (away from zero) 0.999999 and floors the result. µ is the closest thing to an infinitesimal in language's operators. With a properly functioning Trunc(x) command, answer now supports 0 as input.

C# (Visual C# Compiler), 41 bytes27 bytes24 bytes

s=>(int)s+Math.Sign(s%1)

Try it online!

First post here, had fun with it, hope u like it. Kinda felt C# place is empty here

-14 tnx to @expired data
-3 tnx to @night2

C, 94 43 39 bytes

thanks to ceilingcat for 39 bytes

#define f(n)(int)(n>0?ceil(n):floor(n))

TIO

Perl 5 -pF/\./, 35 bytes

$_&&=$F[0]+($_!=int&&$_*(@F-1)/abs)

Try it online!

PHP, 30 bytes

<?=0^$argn-=0<=>fmod($argn,1);

Try it online!

If number is not integer, based on the sign -1 (for negative decimals) or 1 (for positive decimals) is added to it and then integer part of the new number is printed.


PHP, 32 bytes

<?=[ceil,floor][$argn<0]($argn);

Try it online!

Basically outputs floor of input if it is less than 0, else ceil of it.


PHP, 34 bytes

<?=($argn>0?:-1)*ceil(abs($argn));

Try it online!

sed, 131 bytes + 2 bytes for -r flag

/^-?[^.]*(\.0*)?$/bQ
s/^(-?)9/\109/
s/([0-8]9*)\..*$/_\1/
h
s/.*_//
y/0123456789/1234567890/
G
s/(.*)\n(.*)_(.*)/\2\1/
:Q
s/\..*$//

Ungolfed

#!/bin/sed -rf

# identify integers
/^-?[^.]*(\.0*)?$/ b isInt

# add a leading 0 if we'll need it later
s/^(-?)9/\109/

# convert to format: -?[0-9]_[0-8]9*
s/([0-8]9*)\..*$/_\1/

# move the part that will remain constant into the hold buffer
h
s/.*_//

# [0-8]9* can be incremented via character substitution
y/0123456789/1234567890/

# reassemble parts
G
s/(.*)\n(.*)_(.*)/\2\1/

:isInt
# Get rid of anything after the decimal point
s/\..*$//

Vim, 36 bytes/keystrokes

:s/-/-<Space>
:g/\..*[1-9]/norm <C-v><C-a>lD
:s/<Space><cr>

Try it online! or Verify all Test Cases!

Explanation:

:s/             " Replace...
   -            "   A dash
    /-<Space>   "   With a dash and a space

:g/                             " On Every line matching this regex...
   \.                           "   A dot
     .*                         "   Followed By anything
       [1-9]                    "   Followed by a digit other than 0
            /norm               " Run the following keystrokes...
                  <C-v><C-a>    "   Increment the number by 1
                                "   This also conveniently places our cursor just before the dot
                            l   "   Move one character right
                             D  "   Delete everything after the cursor

:s/             " Replace...
   <Space>      "   A space
                "   (With nothing)

APL (Dyalog Unicode), 15 bytes

{⍎'⌈⌊'[0>⍵],⍕⍵}

Try it online!

Simple Dfn. Uses ⎕IO←0.

How:

{⍎'⌈⌊'[0>⍵],⍕⍵} ⍝ Main function, argument ⍵.
            ⍕⍵  ⍝ Stringified argument
           ,    ⍝ Appended to
      [0>⍵]     ⍝ This item... (0 if ⍵ is positive or 0, else 1)
  '⌈⌊'          ⍝ of this string (which are the functions Ceiling and Floor, respectively)
 ⍎              ⍝ Executed as APL code.

MathGolf, 5 bytes

‼σ±ü*

Try it online!

Explanation

It's nice to find usage for the operator.

‼       apply next two operators to (implicit) input
 σ      sign (-1, 0, or 1)
  ±     absolute value
   ü    ceiling of that absolute value
    *   multiply the rounded absolute value with the sign

Zsh, 43 36 35 bytes

Try it online! Try it online! Try it online!

Using nested ternaries, for extra confusion. XOR logic from the round to 0 solution.

x=$1
<<<$[(x^0-x?x+(x<0?-1:1):x)^0]

Explanation:

x=$1                                    #set x
         x^0-x?                         #if x has decimals (shorter than x^0!=x)
                                        #(0 is falsy in this context) 
                    x+(x<0?-1:1)        #  if x<0 subtract 1 else add 1
                                :x      #otherwise the result is just x
<<<$[(                            )^0]  #truncate to int & output

Factor, 57 bytes

: f ( x -- x ) [ signum ] [ abs ceiling ] bi * >integer ;

Try it online!

Scala, 16 bytes

_.setScale(0,UP)

Try it online!

Scala, 22 bytes

x=>x.signum*x.abs.ceil

Try it online!

Java (JDK), 18 bytes

d->d.setScale(0,0)

Try it online!

Explanations

Uses a BigDecimal as input and output. BigDecimal has a method setScale that sets the scale of the number. The first parameter is the number of digits after the dot separator, the second is the rounding mode. ROUND_UP is the "away-from-zero" rounding and has a value of 0 so I hardcode that value.

Perl 6, 18 bytes

{$_-.abs%-1*.sign}

Try it online!

Explanation

{                }  # Anonymous block
    .abs  # Absolute value
        %-1  # Modulo -1
           *.sign  # Multiply by sign
 $_-  # Subtract from original

Wolfram Language (Mathematica), 18 bytes

Sign@#⌈Abs@#⌉&

Try it online!

JavaScript (ES6), 20 bytes

n=>n%1?n<0?~-n:-~n:n

Try it online!

Commented

n =>        // n = input
  n % 1 ?   // if n is not an integer:
    n < 0 ? //   if n is negative:
      ~-n   //     return -(floor(-n) + 1) = -floor(-n) - 1
    :       //   else:
      -~n   //     return -(-(floor(n) + 1)) = floor(n) + 1
  :         // else:
    n       //   return n unchanged

Red, 46 bytes

func[n][(pick[0 1]n = t: to 0 n)*(sign? n)+ t]

Try it online!

The slightly more readable version is 2 byte longer (those long function names!):

func[n][to 1(sign? n)* round/ceiling absolute n]

Jelly, 5 4 bytes

AĊ×Ṡ

Try it online!

This ports recursive's Stax answer into Jelly, so check that answer out for an explanation.

-1 byte thanks to Nick Kennedy

Jelly, 6 5 bytes

ĊḞ>?0

Try it online!

-1 byte thanks to Jonathan Allan

How this one works

ĊḞ>?0 - Monadic link. Takes a float, x, as argument

   ?  - If:
  > 0 -   x > 0
      - Then:
Ċ     -   ceil(x)
      - Else:
 Ḟ    -   floor(x)

Python 3, 23 bytes

lambda i:i-i%(1|-(i>0))

Try it online!

-1 byte thanks to xnor

Japt, 6 bytes

Î*Ua c

Try it here

05AB1E, 6 bytes

ÄîI.±*

A 5-byter should definitely be possible..

Try it online or verify all test cases.

Explanation:

Ä       # The absolute value of the (implicit) input,
 î      # ceiled
     *  # And then multiplied by
   .±   # the signum
  I     # of the input
        # (after which the result is output implicitly)

J, 6 bytes

**>.@|

Try it online!

Just a 1 character change from my answer on the cousin question.

Excel, 13 bytes

=ROUNDUP(A1,)

Alternative

=EVEN(A1*2)/2

Java (OpenJDK 8), 43 bytes

a->{return(int)((int)a/a<1?a>0?a+1:a-1:a);}

Try it online!

Perl 6, 19 bytes

{$_+|0+.sign*?/\./}

Try it online!

Not the shortest solution, but I'm working on it. Basically this truncates the number, then adds one away from zero if the number was not whole to begin with

Retina 0.8.2, 38 bytes

\.0+
.
\b9+\..
0$&
T`9d`d`.9*\..
\..*

Try it online! Link includes test cases. Explanation:

\.0+
.

Delete zeroes after the decimal point, to ensure that the number is not an integer; the next two matches fail if there are no digits after the decimal point.

\b9+\..
0$&

If the integer part is all 9s, prefix a 0 to allow the increment to overflow.

T`9d`d`.9*\..

Increment the integer part of the number.

\..*

Delete the fractional part of the number.

Brachylog, 7 bytes

⌋₁ℤ₁|⌉₁

Try it online!

or ⌉₁ℕ₁|⌋₁.

⌋₁         The input rounded down
  ℤ₁       is an integer less than -1
    |      and the output, or, the input
     ⌉₁    rounded up is the output.

Jelly, 4 bytes

ĊṠ¡Ḟ

A monadic Link accepting a number which yields an integer.

Try it online! Or see a test-suite.

How?

ĊṠ¡Ḟ - Link: number, N
  ¡  - repeat...
 Ṡ   - ...number of times: sign of N (repeating -1 is the same as 0 times)
Ċ    - ...action: ceiling
   Ḟ - floor (that)

R, 32 bytes

x=scan()
sign(x)*ceiling(abs(x))

Stax, 6 bytes

å├╪∙Bß

Run and debug it

Procedure:

  1. Absolute value
  2. Ceiling
  3. Multiply by original sign