Mod the Floats!

Python, 20 bytes

lambda x:x%1or+(x>0)

Try it online!

Takes the input modulo 1, then handles the boundary case by converting outputs of 0 to 1 for positive inputs. A bool output would save two bytes.

lambda x:x%1or x>0

Brachylog, 14 11 bytes

Thanks to Fatalize for golfing 3 bytes.

∧≜:?+.≥0∧1≥

For a change, this answer doesn't use mod :)

Try it online!

Explanation

∧≜                Label an integer variable. This will start trying different
                  values for this variable, the ones closest to 0 first.
   :?+.           This variable summed to the input is equal to the output
      .≥0∧1≥      which is >= 0 and <= 1

JavaScript (ES6), 19 bytes

n=>(n%1+1)%1||n>0|0

In JavaScript, n%x returns a negative number if n is negative, meaning that if we want to get the positive residue, we must add x if n is negative. (n%x+x)%x covers all cases:

n     n%1   n%1+1 (n%1+1)%1
0     0     1     0
1     0     1     0
2.4   0.4   1.4   0.4
-1    0     1     0
-2.4  -0.4  0.6   0.6

Another working solution at 20 bytes, which shows a bit more of a pattern:

n=>n%1+(n%1?n<0:n>0)

Tags:

Code Golf