Convert a decimal to a fraction, approximately Take the decimal number \$0.70710678\$. As a fraction, it'd be \$\frac{70710678}{100000000}\$, which simplifies to \$\frac{35355339}{50000000}\$. If you were to make the denominator \$1\$, the closest fraction is \$\frac{1}{1}\$. With \$2\$, it'd be \$\frac{1}{2}\$, and with \$3\$ it's \$\frac{2}{3}\$. Because \$0.\bar{6}\$ is closer to \$0.70710678\$ than \$\frac{3}{4}\$ or \$\frac{4}{5}\$, it would still be the closest with a maximum denominator up to (and including) \$6\$.
Task
There are two inputs: a decimal, and a maximum denominator.
The first input consists of a number \$n\$ as input, where \$0\le n&lt;1\$, and the fractional part is represented with a decimal (although not necessarily using base 10). This can be represented as a floating point number, an integer representing a multiple of \$10^{-8}\$ (or some other sufficiently smaller number), a string representation of the number, or any other reasonable format.
The second input is an integer \$n\ge1\$, also taken in any reasonable format.
The output should be a fraction, with a denominator \$d\le n\$, where \$n\$ is the second input. This should be the closest fraction to the inputted decimal that is possible with the restrictions placed on the denominator. If there are multiple which are equally close (or equal to the inputted number), the one with the smallest denominator should be chosen. If there are two with the same denominator which are equidistant, either are acceptable.
The outputted fraction can be represented in any reasonable format, as long as it consists of a numerator and denominator, both being natural numbers.
Test cases
0.7         4   -&gt;   2 / 3
0.25285     15  -&gt;   1 / 4
0.1         10  -&gt;   1 / 10
0.1         5   -&gt;   0 / 1
0.68888889  60  -&gt;  31 / 45
0.68888889  30  -&gt;  20 / 29
0.0         2   -&gt;   0 / 1
0.99999999  99  -&gt;   1 / 1

Other
This is code-golf, shortest answer in bytes per language wins!
Scratch 3.0, 45 blocks/254 bytes

As SB Syntax:
define(n)(d)
set[A v]to(0
set[D v]to(d
set[i v]to(0
repeat((n)+(1
set[j v]to(0
repeat((n)+(1
set[r v]to((i)/(j
if&lt;(D)&gt;([abs v]of((r)-(D)))&gt;then
set[A v]to(join(i)(join(/)(j
set[D v]to([abs v]of((r)-(D
end
set[j v]to((j)+(1
end
set[i v]to((i)+(1
end
say(A

Try it on Scratch!
Just wouldn't be right if I didn't do this in Scratch.
Explained
define(n)(d) // Define an empty name function with parameters `n` (the denominator) and `d` (the decimal to fractionify)
set[D v]to(d // This will store the current absolute difference between potential fraction and actual decimal
set[i v]to(0 // outer-cartesian-loop variable
repeat((n)+(1
set[j v]to(0 // inner-cartesian-loop variable
repeat((n)+(1 // simulate cartesian product of range(0, n+1) and range(0, n+1)
set[r v]to((i)/(j // divide i / j
if&lt;(D)&gt;([abs v]of((r)-(D)))&gt;then // if the difference between (i/j) and d is smaller than the current smallest difference
set[A v]to(join(i)(join(/)(j // update answer and difference
set[D v]to([abs v]of((r)-(D
end
set[j v]to((j)+(1
end
set[i v]to((i)+(1
end
say(A // output answer