[Question]
  [
Given a decimal integer `n` as input, output the smallest (in terms of absolute value) decimal integer `m` such that the absolute value of `n-m` is a binary integer (composed only of `1`s and `0`s).
`n` and `m` can be any integer, positive or negative.
### Example
Let `n = 702`. The closest binary integer is `1000 = |702 - (-298)|`, so `m = -298`.
Let `n = -82`. The closest binary integer in absolute value is `100 = |-82 - 18|`, so `m = 18`.
### Test Cases
```
Input n                Output m
0                      0
1                      0
4                      3
-4                     -3
6                      -4
15                     4
55                     44
56                     -44
-82                    18
702                    -298
-1000                  0
```
### Scoring
This is code-golf, so the shortest answer in bytes wins.
  
[Answer]
# JavaScript (ES6), 43 bytes
Starting with \$k=0\$ and using the expression `(k < 1) - k` to update \$k\$ after each iteration, we recursively generate \$k=0,1,-1,2,-2,3,-3,\dots\$ ([A001057](https://oeis.org/A001057)) until the regular expression `/[2-9]/` applied to \$n-k\$ doesn't match anything.
```
f=(n,k=0)=>/[2-9]/.test(n-k)?f(n,(k<1)-k):k
```
[Try it online!](https://tio.run/##dc/BDoIwDAbgu0/BcUss6@ZAMKIPYjwQBIMjm3GLrz85KGCNvf350v7prX7Wvnn09wDWXdoYu4rZtamQVwdxUlCeRRpaH5gFw4/daMzsJR/DzsTGWe@GNh3clXUMk3E4T4RIcPVN8j/pmTaEQE8E1PJ5DTRtyyajlC3ox/LFSYpQqA/KgtgWJwNVUgWJiO/f4ws "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 48 bytes
```
f n=[m|k<-[0..],m<-[k,-k],all(<'2')$show$n-m]!!0
```
[Try it online!](https://tio.run/##DcZBCoMwEAXQq4wQsIU/Mglqu9CThCyyqCjJpKKFbnr3VHiLt8YzvXKudaEye/2lib10XYBeSeAUEHO@Ta1r7@Zc319TWEPTSNW4FZppP7byIUMad1rICyx6cI8RdsBwGcFPh4c4sBWRUP8 "Haskell ‚Äì Try It Online")
xnor saved 7 bytes, thanks!
[Answer]
# [Python 2](https://docs.python.org/2/), 49 bytes
```
f=lambda n,m=0:f(n,(m<1)-m)if"1"<max(`n-m`)else m
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728oLIkIz_PaMGCpaUlaboWNw3TbHMSc5NSEhXydHJtDazSNPJ0NHJtDDV1czUz05QMlWxyEys0EvJ0cxM0U3OKUxVyoRr7C4oy80o00jQMNDW5YGxDJLYJElsXmWOGrMEUiWOKwkFWpmthhMQzN0Dm6RoaGADdAHEWzF8A)
Port of Arnauld's answer, thanks to Kevin Cruijssen.
`"1"<max(`n-m`)` checks if any digits of `n-m` are more than `1`, i.e. `n-m` is not a binary number.
## [Python 2](https://docs.python.org/2/), 68 bytes
```
lambda n:min((m for m in range(-n*n,n*n+1)if"2">max(`n-m`)),key=abs)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728oLIkIz_PaMHiNNuYpaUlaboWN11yEnOTUhIV8qxyM_M0NHIV0vKLFHIVMvMUihLz0lM1dPO08nSAWNtQMzNNyUjJLjexQiMhTzc3QVNTJzu10jYxqVgTalZ_QVFmXolGmoaBpiYXjG2IxDZBYusic8yQNZgicUxROMjKdC2MkHjmBsg8XUMDA6AbIM5asABCAwA)
The requirement to handle negative numbers is annoying.
Pretty na√Øve brute-force type method.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
LbI.x-
```
[Try it online](https://tio.run/##yy9OTMpM/f/fJ8lTr0L3/39dCyMA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaXLf5@kSr0K3f86/6MNdAx1THR0TXTMdAxNdUyByExH18JIx9zASEfX0MDAIBYA) or [see this step-by-step output](https://tio.run/##Vc2/CsIwEMfx3ac4OqeCTiJIB6diN0dxuNTTHMSk5E/VF/MBfLFoUkRcf3zuvtajZEqpas0QwxoqsXk9m1m1tWYkF4ADBAsIh4Uwx9qhudAJNPtCu39L2KusJRt0jwzkBHZEAwRFMKKOBL22nnx5nEf@ltv5ffL7KIPDvtTPzl5/TMBN8afCvmyOfNTltm5SqlfLNw).
**Explanation:**
```
L       # Push a list in the range [1, (implicit) input-integer]
 b      # Convert each to a binary-string
  I     # Push the input-integer again
   .x   # Pop both, and keep the binary-string that's closest to the input
     -  # Subtract it from the (implicit) input-integer
        # (after which the result is output implicitly)
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 22 bytes
```
{(|/49<$x-){-x-x<1}/0}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6rWqNE3sbRRqdDVrNat0K2wMazVN6jl4jJMi1FXMFAwVDBR0DVRMFMwNFUwBSIzBV0LIwVzAyMFXUMDAwMAArcOKA==)
-3 bytes thanks to @coltim!
Port of [Arnauld's answer](https://codegolf.stackexchange.com/a/248925/41247).
My first-ever K submission! Been having a lot of fun learning all these APL-esque languages.
---
# [K (ngn/k)](https://codeberg.org/ngn/k), 34 bytes
```
{*a@<a|-a:x-,/-:\.'""/'$+!2,2|^$x}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6rWSnSwSazRTbSq0NXR17WK0VNXUtJXV9FWNNIxqolTqajl4jJMi1FXMFAwVDBR0DVRMFMwNFUwBSIzBV0LIwVzAyMFXUMDAwMAvYsQgA==)
Wanted to find another approach, but it ended up becoming @Jonah's approach.
## Explanation
Input is *x*.
* `+!2,2|^$x` binary sequences of (length of *x*)+1
* `.'""/'$` join each binary sequence and convert to decimal
* `,/-:\` append negatives
* `x-` subtract *x* from each
* `*a@<a|-a:` absolute minimum
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 193 bytes
```
[S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][N
S S N
_Create_Label_OUTER_LOOP][S N
S _Duplicate_m][S S S N
_Push_0][T  T   T   _Retrieve_input][S N
T   _Swap_top_two][T    S S T   _Subtract_:_input-m][S N
S _Duplicate_input-m][N
T   T   S N
_If_neg_jump_to_Label_ABS][N
S S T   N
_Create_Label_INNER_LOOP][S N
S _Duplicate_abs(input-m)][N
T   S S S N
_If_0_jump_to_Label_PRINT_RESULT][S N
S _Duplicate][S S S T   S T S N
_Push_10][T S T T   _Modulo_:_abs(input-m)%10][S S S T  S N
_Push_2][T  S S T   _Subtract_:_abs(input-m)%10-2][N
T   T   S T N
_If_neg_jump_to_Label_CONTINUE_INNER][S N
N
_Discard_top][S S T T   N
_Push_-1][T S S N
_Multiply_:_-m][S N
S _Duplicate][N
T   T   T   S N
_If_neg_jump_to_Label_NON_NEG][S N
S _Duplicate][N
T   S T S N
_If_0_jump_to_Label_NON_NEG][N
S N
N
_Jump_to_Label_OUTER_LOOP][N
S S S N
_Create_Label_ABS][S S T    T   N
_Push_-1][T S S N
_Multiply_:_abs(input-m)][N
S N
T   N
_Jump_to_Label_INNER_LOOP][N
S S S T N
_Create_Label_CONTINUE_INNER][S S S T   S T S N
_Push_10][T S T S _Integer_divide_:_abs(input-m)//10][N
S N
T   N
_Jump_to_Label_INNER_LOOP][N
S S T   S N
_Create_Label_NON_NEG][S S S T  N
_Push_1][T  S S T   _Subtract_:_-m-1][N
S N
N
_Jump_to_Label_OUTER_LOOP][N
S S S S N
_Create_Label_PRINT_RESULT][S N
N
_Discard_top][T N
S T _Print_to_STDOUT_as_integer]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.  
`[..._some_action]` added as explanation only.
Just like [my Java answer](https://codegolf.stackexchange.com/a/248926/52210), this is an iterative port of [*@Arnauld*'s JavaScript answer](https://codegolf.stackexchange.com/a/248925/52210).
[**Try it online**](https://tio.run/##TY5BCsNADAPP41foA7n0lO@EEEhvhRT6/I1lN21YMNJIa/zZn@/teC3rNoakyEdAtDQBPCSMbJITZfSr4TgHpZ14TfVcx6T/wFeoVoVz/TtOChG3tbow6oy@IfrGFOkYY5ofJw) (with raw spaces, tabs and new-lines only).
**Explanation in pseudo-code:**
```
Integer m = 0
Read STDIN as integer
Start OUTER_LOOP:
  Integer t = abs(input - m)
              (abs is necessary because of the modulo-10 on negative values)
  Start INNER_LOOP:
    If t ==0:
      Print m as integer to STDOUT
      (implicitly stop the program with an error: no exit defined)
    Integer p = t modulo-10
    If p-2 <0 (thus either 0 or 1):
      t = t integer-divided by 10
      Continue INNER_LOOP
    m = -m
    If m <=0:
      m = m - 1
      Continue OUTER_LOOP
    Continue OUTER_LOOP
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 78 bytes
```
p;r;m;f(n){for(r=m=0;r=!r;m=r?m:(m<1)-m)for(p=abs(n-m);p;p/=10)r&=p%10<2;n=m;}
```
[Try it online!](https://tio.run/##XVDbTsMwDH3nK0yloWRLtbRjsJEFHhBfwfZQsnRUkCxKKlEx9dcp7mUVI7KP7GP7KLaKD0o1jRNeGJETS0/50RMvjeTCy2tkpX8yD8RsEhob2hadzN4CsZgJJ9xcJpz6G@kmCd@kwkoj6qawJZissITC6QrwtUSpQxledyDhxBkkDG4ZxOh3mCwZLFvHOF6lDO45QpxwzmsxCujKaVXq/aiBtsC2Ra/TWieJkKwwSNeIZwF1tKEE9Z75KaJWH9r3OtG2ekm31foZfRkx@JsvomEa9wbS/qGwe13hGBdDuIFQfOtjTs6/o/OBmI6MgNms66adWH@S8Syo1p@ma9mJi2rAak5KeslqZMdr/B9zHltyEk32ED8C4iRsLS5WMghs3D1IqXeDbH1VNz8q/8wOoYm/fgE "C (gcc) ‚Äì Try It Online")
Uses [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)'s idea from his [Javascipt answer](https://codegolf.stackexchange.com/a/248925/9481) to generate \$m=0,1,-1,2,-2\dots\$
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, ~~73~~ ~~66~~ 62 bytes
```
[ 0 [ 2dup - >dec "-01" ‚äÇ ] [ dup 1 < 1 0 ? swap - ] until ]
```
A port of @Arnauld's [JavaScript answer](https://codegolf.stackexchange.com/a/248925/97916). Needs modern Factor for [>dec](https://docs.factorcode.org/content/word-__gt__dec,math.parser.html), so no TIO/ATO link. Here's a version that works on TIO for 2 more bytes, though:
[Try it online!](https://tio.run/##PY29CsIwHMT3PsXRPSUpbRUVHMXFRZxKh5D@xWKb1nwgIi6OPqYvUpNFuBvu7gd3lsqNZj4d94fdClcymnoM0l0wGbKkHSzdPGlFNjbOPSbThTYimdedGlvCOkme4BAowApUECXKoApsmWPBczDBOcdrrgNVI2/9BPY/SBkX6ffzRhO2OAlsgjm2sHcZyQZeu65HMw8hZ1A9STP/AA "Factor ‚Äì Try It Online")
[Answer]
# [Scala](http://www.scala-lang.org/), 54 bytes
```
n=>(-n*n to n*n)filter(m=>(n-m+"").max<50)minBy(_.abs)
```
A bit late to the party. All tricks I came up with were already in use by somebody else. However, the `-n*n to n*n` trick by *@pxeger* was new to me, thanks!
[Try it online!](https://tio.run/##bZBRT4MwFIXf@RVHsgeq7cLm0LkMEpe4aHxYgj/AdKMkGCgInW4x@@14BwN88KU9p/3u6b2tdjKVdb79UDuD5/x7Lct1mWerRMvyCHUwSkcVHosCPxYQqRjxAi/awA/ardZ@4Ah9rWFy0MbiJDWqdDI61iK7sW02zuRh6bksS/Tq6LyP5bZiNaV9yZRekFmRqgo@3tSnQ6eA43KX8VZOBjnjt50UMy56c8fFrMc93muP9GDOVO/EfMon887du1Mupg@9FxPXPbdAjlm0xHnZTE9XiS72hlPXBf2XihiWoh@hIfK9IYKmiVv2HHK6VBdlok2q2yGBJIbT4f4QebkFKnvzigVGTQ5EgFFL2xdCpZX6Az@F4Sb8j8eVj1EX3xY3XVmn@hc "Scala ‚Äì Try It Online")
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 57 bytes
[-4 thanks to Neil](https://codegolf.stackexchange.com/questions/248922/how-far-from-binary#comment556309_248963)
```
int@B(int@n,int@m=0)=>$"{n-m}".Max()<50?m:B(n,m<0?-m:~m);
```
[Try it online!](https://tio.run/##Sy7WTS7O/P8/M6/EwUkDRObpgMhcWwNNWzsVpeo83dxaJT3fxAoNTRtTA/tcKyeNPJ1cGwN73VyrulxN6//O@XnF@TmpeuFFmSWpPpl5qRpAXU4aBpq1SprWXDhkDfHKmuCV1cUvbYbfYlO80qYEpPEbrmthhFfe3AC/vK6hgQE03P4DAA "C# (Visual C# Interactive Compiler) ‚Äì Try It Online")
Kinda abuses the fact that the Visual C# Interactive Compiler mode seems to import System.Linq by default.
A version that doesn't use Linqin 87 bytes
```
int@B(int@n,int@m=0)=>$"{n-m}".IndexOfAny("23456789".ToCharArray())<0?m:B(n,m<0?-m:~m);
```
[Try it online!](https://tio.run/##Sy7WTS7O/P8/M6/EwUkDRObpgMhcWwNNWzsVpeo83dxaJT3PvJTUCv80x7xKDSUjYxNTM3MLSyW9kHznjMQix6KixEoNTU0bA/tcKyeNPJ1cIEs316ouV9P6v3N@XnF@TqpeeFFmSapPZl6qBtBMJw0DzVolTWsuHLKGeGVN8Mrq4pc2w2@xKV5pUwLS@A3XtTDCK29ugF9e19DAABpu/wE "C# (Visual C# Interactive Compiler) ‚Äì Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 8 bytes
```
;.‚âú-·∫π~·∏É‚àß
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3w31rvUecc3Ye7dtY93NH8qGP5///RBjoKhjoKJjoK8UBsBuSY6iiYgjCQHW9hpKNgbgAk4g0NDAxiAQ "Brachylog ‚Äì Try It Online")
Something less *blunt* seems possible.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 9 bytes
*Edit: bug fixed thanks to Kevin Cruijssen (same bytes)*
```
·∏ü»ØŒõŒµd‚â†‚Å∞ƒ∞Z
```
[Try it online!](https://tio.run/##AR8A4P9odXNr///huJ/Ir86bzrVk4omg4oGwxLBa////NzAy "Husk ‚Äì Try It Online")
```
·∏ü          # find the first element of
       ƒ∞Z  # the infinite sequence of positive & negative integers 0,1,-1,2,-2,3,...
 »Ø         # that satisfies (composition of 3 functions):
  Œõ        # all of the
    d      # decimal digits of the
     ‚â†‚Å∞    # absolute difference to the input
   Œµ       # are at most 1
```
[Answer]
# [J](http://jsoftware.com/), 45 41 40 38 bytes
```
-0{[(]/:|@-/)[:(,-)10#.[:#:@i.2^1+#@":
```
[Try it online!](https://tio.run/##dZDBCoJAEIbv8xRDHlRydFZXs4VACIIgCLpKeYgkg6yDQlDvbnpYg1gHFj7225lh/1s38@0SVwpt9JBR9Yd8XB92m474nTvHQH0yCtxcOR65gi0/V5bKKj88ibmVzVTnwuV8fWCJrEFokBqKkZLxUawp/tFoizTUuOARC8Hcb3lVjW3Dtn62Ddb4V/u2Ge7vwGgsBjElpFlEQGZDESTmFpIgYqOREE@I3iQTwyRQGpqUSKGPx9gULlOgIS/DT7sv "J ‚Äì Try It Online")
*-4 thanks to Kevin Cruijssen*
This is much longer than a port of Arnauld's answer would have been, but I figured a different conceptual approach might be interesting, and in another language the approach might even be shorter:
Consider 702:
* It's length is 3.
* Generate integers 0... 2^3, in binary:
```
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
```
* Convert them to decimal
```
0 1 10 11 100 101 110 111
```
* Add their negative values too:
```
0 1 10 11 100 101 110 111 0 _1 _10 _11 _100 _101 _110 _111
```
* Also add `10^<length of input> = 1000`
```
0 1 10 11 100 101 110 111 0 _1 _10 _11 _100 _101 _110 _111 1000
```
* Find which of these numbers has the smallest absolute different with the input:
```
1000
```
* Original input minus that.
```
_298
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 53 bytes
```
f=->n,k=0{(n+k).to_s=~/[2-9]/?f.call(n,k<0?-k:~k):-k}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y5PJ9vWoFojTztbU68kP77Ytk4/2kjXMlbfPk0vOTEnRwOowMbAXjfbqi5b00o3u/Z/gQJUxkCTC842RGKbILF1kTlmyBpMkTimKBxkZboWSBxzAyNkKUMDAwPN/wA "Ruby ‚Äì Try It Online")
Port of [Arnauld's answer.](https://codegolf.stackexchange.com/a/248925/112099)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 15 bytes
```
0Œª?Œµf1>a;‚Çç><‚ÅΩ»ß‚àµ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIwzrs/zrVmMT5hO+KCjT484oG9yKfiiLUiLCIiLCI3MDIiXQ==)
## How?
```
0Œª?Œµf1>a;‚Çç><‚ÅΩ»ß‚àµ
         ‚Çç      # Apply both of the following two commands and wrap the results in a list:
          >     #  Increment until lambda returns false...
           <    #  and decrement until lambda returns false.
 Œª      ;       # With the following lambda:
  ?Œµ            #  Absolute difference with input
    f           #  List of digits
     1>a        #  Are there any that are greater than 1?
0               # ...starting from 0.
            ‚ÅΩ»ß‚àµ # Take the minimum of these two by the absolute value.
```
Another 15 byter: `N·π°:»ßbv·πÖ‚åä$¬±*-‚ÅΩ»ß‚àµ`. In fact, `:»ßbv·πÖ‚åä$¬±*` is all to create a binary string, but handling negative values.
[Answer]
# [Haskell](https://www.haskell.org), 84 bytes
```
f n=head$filter(all(`elem`"-10").show.(n-))$concat$zipWith(\a b->[a,b])[0,-1..][1..]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8GCpaUlaboWN0PSFPJsM1ITU1TSMnNKUos0EnNyNBJSc1JzE5R0DQ2UNPWKM_LL9TTydDU1VZLz85ITS1SqMgvCM0syNGISFZJ07aITdZJiNaMNdHQN9fRio0EExGyoFTCrAA)
[Answer]
# BQN, 29 bytes
```
{'1'<‚åà¬¥‚Ä¢Fmt|ùï®-ùï©?ùï®ùïä<‚üú1‚ä∏-ùï©;ùï©}‚üú0
```
[Try it here!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAgeycxJzzijIjCtOKAokZtdHzwnZWoLfCdlak/8J2VqPCdlYo84p+cMeKKuC3wnZWpO/Cdlal94p+cMAoK4oCiU2hvd+KImEbCqOKfqAowCjEKNAotNAo2CjE1CjU1CjU2Ci04Mgo3MDIKLTEwMDAK4p+pCkA=)
Port of [Arnauld's answer](https://codegolf.stackexchange.com/a/248925/41247).
[Answer]
# Java 8, ~~69~~ 68 bytes
```
n->{int m=0;for(;!(n-m+"").matches("[01-]+");m=m<0?-m:~m);return m;}
```
Iterative port of [*@Arnauld*'s JavaScript answer](https://codegolf.stackexchange.com/a/248925/52210), and an additional -1 thanks to *@Arnauld* as well.
[Try it online.](https://tio.run/##PY/BTsMwEETv/YrFp1ixI6dqC4oJHDjTS48hB@O6kBI7VbwpQlH49WCXgrQaaWelN7NHdVb8uP@Ydau8h2fVuHEB0Dg0/UFpA9u4XgzQSVRHZXCmRRCPChsNW3BQzo4/jPFuSyEPXZ/Im8RxmxJCM6tQvxufkErkvE4Jlba09@KR2@LbUtkbHHoHVk6zjNjT8NoG7JV@7po92NAr2WHfuLeqVvS3U0yJiWg8PilvoABnPmPVqh4Fy9mK8RXbsHzN1mE2jN8t2a1YMp4LISZ6gQDsvjwam3UDZqcQgK1L/ogpKV6QpC7T/xa9vj/NPw)
**Explanation:**
```
n->{                      // Method with integer as both parameter & return-type
  int m=0;                //  Result-integer, starting at 0
  for(;!(n-m+"")          //  Loop as long as n-m converted to a String
        .matches("[01-]+")//  contains anything other than just 0s/1s/"-"s
      ;                   //    After every iteration:
     //m=m<0?-m:~m        //     (iterate to the next `m` in 0,1,-1,2,-2,3,...)
       m=                 //     Update the result to:
         m<0?             //      If the result is negative:
             -m           //       Change it to its positive form
               :          //      Else (it's 0 or positive):
                ~m)       //       Change it to -m-1 instead
  ;                       //  After the loop,
   return m;}             //  simply return the result
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 41 bytes
```
Fh,2{W$|1<_M^aAD(h?iv){h?UiDv}}ABi<ABv?iv
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgWbSSboFS7IKlpSVpuhY3Nd0ydIyqw1VqDG3ifeMSHV00MuwzyzSrM-xDM13KamsdnTJtHJ3KgGIQDVB9S6PNDYxghgAA)
Argh.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 112 bytes
```
$
¬∂$`
(¬∂-?)(([01]*)0)?(5*[6-9].*)
$1${3}1$.4$*0
(¬∂[-01]*)([2-9].*)
$1$.2$*1
\d+
$*
(1*)¬∂-?\1
-
--
r`(1*)-*$
$.1
```
[Try it online!](https://tio.run/##RcwxCsJAEIXh/p1jhNmRWWbWJGqV0kNsAitoYWMR0onXygFysdXYCK/6@XjTfX48r3XHl1IJ60IFvC7aB@ZsPkqw0HMrudPzGCWAnF6Ht1NsSGyjWX@Mc/qLmEgcw20PErBL2B4Hh0IVmMqWVAgUvVaDo4E26OAt2u866CnhaAnqZvYB "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. Explanation:
```
$
¬∂$`
```
Duplicate the input.
```
(¬∂-?)(([01]*)0)?(5*[6-9].*)
$1${3}1$.4$*0
```
If the second copy has a digit between `6` and `9`, optionally preceded by any number of `5`s, either at the start of the number or after a `0`, then round those `5-9`s away from zero. For example, `-1056` rounds to `-1100`.
```
(¬∂[-01]*)([2-9].*)
$1$.2$*1
```
Otherwise if it still has a digit of at least `2` then "round it towards zero" (fill with `1`s). For example, `19` rounds to `11`.
```
\d+
$*
```
Convert to unary.
```
(1*)¬∂-?\1
-
```
Subtract the two numbers.
```
--
```
If we subtracted a more negative number from another, the result is now positive. (This saves a byte over doing it in the decimal conversion.)
```
r`(1*)-*$
$.1
```
Convert to decimal, ignoring any trailing `-`s which result when the first number's absolute value is no less than the second.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
rNB·∏å‚Å∏_A√ê·πÇ
```
[Try it online!](https://tio.run/##y0rNyan8/7/Iz@nhjp5HjTviHQ9PeLiz6f/hds3I//8NdBQMdRRMdBR0gdgMyDHVUTAFYSBb18JIR8HcAEjoGhoYGAAA "Jelly ‚Äì Try It Online")
Absolutely awful...
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 22 bytes
```
ÔºÆŒ∏‚âî‚Å∞Œ∑Ôº∑‚Äπ1‚åàÔº©‚ÅªŒ∏Œ∑‚âî‚Åª‚ÄπŒ∑¬πŒ∑Œ∑Ôº©Œ∑
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05rLsbg4Mz1Pw0BHIQPIK8/IzElV0PBJLS7WUDJU0lHwTazIzC3N1XBOLC7R8M3MKy3WKAQpBQEFqF6IMFhPho6CoSZIHmJcQFFmXglEL1CL9f//5gZG/3XLcgA "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation: Port of @pxeger's Python port of @Arnauld's JavaScript answer.
```
ÔºÆŒ∏
```
Input `n`.
```
‚âî‚Å∞Œ∑
```
Start testing with `m=0`.
```
Ôº∑‚Äπ1‚åàÔº©‚ÅªŒ∏Œ∑
```
Repeat while `n-m` contains a digit greater than `1`.
```
‚âî‚Åª‚ÄπŒ∑¬πŒ∑Œ∑
```
Get the next value of `m` to test.
```
Ôº©Œ∑
```
Output the found value of `m`.
31 bytes for an efficient version that uses @Jonah's alternative approach:
```
ÔºÆŒ∏‚âîÔº©Ôº•‚äïÔº∏¬≤Ôº¨Œ∏‚çòŒπ¬≤œÖ‚âî‚ÅªŒ∏‚Å∫œÖ¬±œÖœÖÔº©¬ßœÖ‚åï‚ÜîœÖ‚åä‚ÜîœÖ
```
[Try it online!](https://tio.run/##Tc3BCsIwDAbgu0/RYwYVZBcPO01BGLgx8Am6LXSFLtvaVH37WieouQR@vvzpR@X6WdkYK1oCN2Hq0MGaFbvSe6MJzsoz1GqBinqHExLjAO38SCqX4oqkeUw@y6Q4KY83doY0GCnyLQu/ptpQ8LBK0dq0gxQNasUI4QvbdMufjyVXNODzzS6GBig7P9uwaSlSk5nC9B9uU8R4PORxf7cv "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation:
```
ÔºÆŒ∏
```
Input `n`.
```
‚âîÔº©Ôº•‚äïÔº∏¬≤Ôº¨Œ∏‚çòŒπ¬≤œÖ
```
Generate all the base `2` values from `0` to the first value whose length in base `2` exceeds `n`'s length, and interpret the base `2` values as base `10`.
```
‚âî‚ÅªŒ∏‚Å∫œÖ¬±œÖœÖ
```
Append the negations of those values, and then subtract all of them from `n`.
```
Ôº©¬ßœÖ‚åï‚ÜîœÖ‚åä‚ÜîœÖ
```
Output the value with the lowest absolute value.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 15 bytes
```
-QhaDQ.m-`bT+Uy
```
[Try it online!](https://tio.run/##K6gsyfj/XzcwI9ElUC9XNyEpRDu08v9/CyMA "Pyth ‚Äì Try It Online") or [Try all test cases](https://tio.run/##K6gsyfiv/F83MCPRJVAvVzchKUQ7tDIwUMHW9f9/Ay5DLhMuXRMuMy5DUy5TIDLj0rUw4jI3MOLSNTQwMAAA "Pyth ‚Äì Try It Online")
```
-QhaDQ.m-`bT+Uy(QQ)
                    # Implicitly initialize Q as the input
             UyQ    # Range from 0 to 2*Q (half-inclusive)
            +   Q   # Append Q (necessary for the 0 case)
      .m            # Filter for elements `b` that are minimized by...
        -`b         #  ...the string representation of `b` minus...
           T        #  ... the characters in "10"
   aDQ              # Sort by absolute difference from Q
  h                 # Take the first element
-Q                  # Subtract that from Q
```
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 52 bytes
```
n->k=0;while(n-k&&vecmax(digits(n-k))>1,k=(k<1)-k);k
```
[Attempt This Online!](https://ato.pxeger.com/run?1=LYxdCsIwEISvsvShJLALibRaqMkVPICIFG1rSBtCjX9n8aUg4pm8jSn1YXbmW5h5fnw1mH3rx1cD6n0JDRXfzJG2SpS3k-lq5sim6bU-9NWdHU1rwnl6ca4lWsXsWvJIpf13N5X33YM5IA1-MC7EmEyQQMMc5whbgSARMgSKWkbIEfJJMVOxQFiJeEgKIXZ8nh3H2X8)
A port of [@Arnauld's JavaScript answer](https://codegolf.stackexchange.com/a/248925/52210).
[Answer]
# [Perl 5](https://www.perl.org/) + `-al060p`, 36 bytes
```
$_="@F"-($\=($\<1)-$\)while/[2-9]/}{
```
[Try it online!](https://dom111.github.io/code-sandbox/#eyJsYW5nIjoid2VicGVybC01LjI4LjEiLCJjb2RlIjoiJF89XCJARlwiLSgkXFw9KCRcXDwxKS0kXFwpd2hpbGUvWzItOV0vfXsiLCJhcmdzIjoiLWFsMDYwcCIsImlucHV0IjoiNzAyIn0=)
## Explanation
A translation of [@Arnauld's JavaScript answer](https://codegolf.stackexchange.com/a/248925/9365). `$\` is initialised to `0` via the `-l060` flag and `$_` is set to the original number (stored in `@F` at index `0` via `-a`, interpolated as `"@F"`) with `$\` subtracted, and can then be matched via bare `m//` for digits `2`-`9`.
]