[Question]
  [
## Task:
Your task is, when given three inputs:
* a numerator `n`
* a denominator `d`
* another integer, `x`
Create a program/function that finds the `x`th digit of the number after the decimal place.
## Specs:
* The range of `n` and `d` is between `1` and `2^31 - 1`, inclusive.
* The range of `x` is between `1` and `10,000,000`, inclusive.
	+ You may choose to use 1-based indexing or 0-based indexing for `x`. Please state in your answer which one you're using.
* `n` may be larger than `d`.
* `n`, `d` and `x` are guaranteed to be positive integers (for 1-based index version of `x`, if you choose to use 0-based indexing for `x` then `x` can be `0`).
* You may take inputs in any reasonable way (I.e. any way that is not a standard loophole).
## Rules:
* You must return the exact `x`th digit, not when rounded - so the `15`th digit of `1/6`, for example, is not `7`, but `6`.
* Your program must work for all `x` under 10 million, unless your language doesn't support decimals to 10 million places.
## Example I/O:
*The example input uses 0-based indexing, which means `x` will go from `0` to `9,999,999`. As well as that, the "input" is written as a string with spaces separating the numbers.*
```
1 2 3: 0
5 6 0: 8
5 6 1: 3
1 6 15: 6 (not 7, as it's not rounded)
1 11 2: 0
1 10000 9999999: 0
11 7 1: 7
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), 25 bytes
Port of my Haskell answer, since Python also supports bignums by default. As there, `x` is 1-indexed.
```
lambda n,d,x:n*10**x/d%10
```
[Try it online!](https://tio.run/nexus/python2#LYrBDsIgDEDvfEUvJkCaSKfOZIlHv2J6QGGRZEMyMeLXIxv20PeavuF0yaOebkaDR4Op85KUlGlrNqRynL8dg8/DjZaTKAphdj7CwKXz4R25EMymuw0Rzivc04N@gS1pLW3uCRvcX1l/wBbpz6aQlrtdhQh3VVSZupVa4vI5LvUP "Python 2 – TIO Nexus") (borrowing Keerthana Prabhakaran's wrapper.)
[Answer]
## Mathematica 33 Bytes
```
RealDigits[#/#2,10,1,-#3][[1,1]]&
```
1-based indexing.
e.g. 10-millionth digit of Pi right of the decimal point:
```
%[Pi,1,10^7]
7
```
takes about 2 seconds on my old machine.
You can try it online at [WolframAlpha](http://www.wolframalpha.com/input/?i=RealDigits%5B%23%2F%232,%2010,%201,%20-%233%5D%5B%5B1,%201%5D%5D%20%26%5BPi,%201,%2011%5D)
(click the equal sign)
[Answer]
# [Haskell](https://www.haskell.org/), 26 bytes
Works for all test cases. Yay bignums!
`(n#d)x` takes `Integer`s and returns an `Integer`. `x` is 1-indexed.
```
(n#d)x=n*10^x`div`d`mod`10
```
[Try it online!](https://tio.run/nexus/haskell#JYpBDsIgFET3nIJEF61pCL9qXXESo4H4aSSR3waq5fYI7SzmvUzGG0fK0WKDeS3HL30c2Si8mZv4nlYxVuXBGhTrFDC2Yjuw8U4ddumhGjpgm/IORSeQz6TR/TRqP6EGmTPwnl/YlQ8ctu4ZVB8KAPi5QpbsLSWwst7K6w8 "Haskell – TIO Nexus")
[Answer]
# PHP>=7.1, 40 Bytes
```
<?=bcdiv(($a=$argv)[1],$a[2],$a[3])[-1];
```
[bcdiv](http://php.net/manual/en/function.bcdiv.php)
[Online Version](http://sandbox.onlinephpfunctions.com/code/bcba44f9eceb6971913dc22b05e8217c6ff4cd96)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
⁵*×:ƓDṪ
```
[Try it online!](https://tio.run/nexus/jelly#@/@ocavW4elWxya7PNy56v9/8/8m/40B "Jelly – TIO Nexus")
A function submission (but also works as a full program). Jelly functions can only take two arguments directly; thus I take the digit to return as the left argument, the numerator as the right argument, and the denominator from standard input (in lieu of using a third argument). 
People used to Jelly may be aware that a *full program* can take more than two arguments, but doing so causes you to lose access to the tersest way to write the constant integer 10, which is fairly relevant here. As such, this sort of mixed input feels somewhat like an exploit rather than actual useful golfing; I personally disagree with it, but [the rule about allowing this](https://codegolf.meta.stackexchange.com/a/5415/62131) is presently at +40 / -12, so as long as it's in the rules, I may as well exploit it (and pretty much have to to be competitive).
A left argument of 1 refers to the digit immediately after the decimal point (the ".1s digit"), an argument of 2 to the .01s digit, and so on.
## Explanation
```
⁵*×:ƓDṪ
⁵*        10 to the power of {the left argument}
  ×       multiplied by {the right argument}
   :      divided by
    Ɠ                standard input
      Ṫ   take the last
     D                  decimal digit
```
Jelly has arbitrary-precision arithmetic on integers, so by pre-multiplying by a power of 10, we're effectively moving the digit we want to the units position, where it's much easier to extract.
[Answer]
# [sed](https://www.gnu.org/software/sed/) `-r`, 93 ~~131~~ ~~136~~ bytes
```
s/$/,/
:d
s/,.+/,/
:
s/(1+)(1*;\1;1*,)1{10}?/\21/
t
s/1*/&&&&&&&&&&/
ta
:a
s/1,/,/
td
s/.+,//
```
[Try it online!](https://tio.run/##XUy7DsIwDNz9HQi1iVtzjM3Aj3SpVAYWikg2xK/j2gi1CidL97B9@TqrZjkICw0zZeE@frXJBrFtENKIhMAtXji9LzKeIVRsjSDHDRZNNEwes/8X7@oji6jauw8IjoQf/Vnzu65BVbRX1efGn@VRbss9a/dcAQ "sed 4.2.2 – Try It Online")
([See output in decimal](https://tio.run/##XY7NCoMwEITveQ4p/qSOG7U/5tAXkYJgKb1oabyJr950N5SKHQLf7GQzxN167x0iaKimVw46z4JnG1OWxJTaliylOqGZiuWC1hDUxNeUYvcTR51qOom1vJ@kK880INFcL6hh2REM7my4pJTAGFTCmnAINDgGljgFVjgLrxEKeM8/kUOKRJa@@Bt5Xv1WahOtVdt15nt8To9xcH7/@gA))
Takes input in unary and outputs in unary, and the program is 1-indexed. Thankfully, this [challenge](https://codegolf.stackexchange.com/a/114851/41805) has already prepared me for this one.
The concept is similar, both implement long division. Here, I perform long division `x` times, where `x` is the digit after the decimal place that I have to find. After each iteration, I discard the previous decimal places because they are no longer needed.
While doing division, the program is in the format `dividend;divisor;x,result`.
`s/$/,/` adds this comma, the comma is required to separate the result from everything else
Then follows the main program loop
`:d` label d
* `s/,.+/,/` remove everything after the comma
* `:` empty label
* + `s/(1+)(1*;\1;1*,)1{10}?/\21/` perform division, adding 1 to the result each iteration, whilst simultaneously removing blocks of 10 continuous 1s in the result
* `t` branch to the empty label, in other words, loop until the dividend has been exhausted
* `s/1*/&&&&&&&&&&/` multiply the dividend by 10 to prepare for the next iteration
* `ta` branch to label a
* `:a` label a, this line and the line above are required to make `td` work
* `s/1,/,/` subtract 1 from x
`td` conditional branch to d, this is triggered if there has been a successful substitution since the last conditional branch, since `s/1*/&&&&&&&&&&/` is always successful, `td` will always get triggered, but by introducing branch a, we fix that so that it only depends on the previous substitution
`s/.+,//` finally, remove everything but the result
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~34~~ 33 bytes
```
->n,d,x{(0..x).map{n=n%d*10};n/d}
```
[Try it online!](https://tio.run/nexus/ruby#S7P9r2uXp5OiU1GtYaCnV6Gpl5tYUJ1nm6eaomVoUGudp59S@79AIS3aUMdIxziWC8Q01THTMUAwDSFMQxDTFMY2BKqHsw2AAEICAVTUUMccqPM/AA "Ruby – TIO Nexus")
[Answer]
# REXX, 76 bytes
(Not very short but thought it would make a change to do one in REXX)
Rexx is 1-based by defintion.
```
arg n d x
numeric digits x+10
y=n/d
parse var y "." +(x) z
say left(z,1,"0")
```
Explanation:
1. Read input to the numbers
2. Guarantee enough significant digits (default is 9)
3. Calculate
4. Split. Find the decimal point, count forward "x" characters, take the following characters and put into "z"
5. Print out first digit. Pad with 0 to be sure.
Merging 3 and 4 actually makes it longer because of the change in syntax:
```
parse value n/d with "." +x z +1
```
For non-REXXers: Strings and numbers are totally interchangeable in REXX. They are determined by how you act on them. So you can parse a number using sting functions with no conversion.
For example
```
"27" + "28"
```
returns 55 and not 2728!
[Answer]
## Batch, 70 bytes
```
@set n=%1
@for /l %%x in (0,1,%3)do @set/an=n%%%2*10
@cmd/cset/an/%2
```
[Answer]
# Assembly Intel x86 cpu language, 50 bytes
```
00000940  53                push ebx
00000941  8B5C240C          mov ebx,[esp+0xc]
00000945  8B4C2410          mov ecx,[esp+0x10]
00000949  31C0              xor eax,eax
0000094B  48                dec eax
0000094C  81C102000000      add ecx,0x2
00000952  721A              jc 0x96e
00000954  81FB00000000      cmp ebx,0x0
0000095A  7412              jz 0x96e
0000095C  8B442408          mov eax,[esp+0x8]
00000960  31D2              xor edx,edx
00000962  F7F3              div ebx
00000964  49                dec ecx
00000965  7407              jz 0x96e
00000967  8D0492            lea eax,[edx+edx*4]
0000096A  01C0              add eax,eax
0000096C  EBF2              jmp short 0x960
0000096E  5B                pop ebx
0000096F  C20C00            ret 0xc
```
traslation in nasm
```
; u32 __stdcall rdiv(u32 a, u32  b, u32 c)
; 8a, 12b, 16c
      align   4
rdiv:                   ; c<0xFFFFFFFE and b!=0
      push    ebx       ; something as for(;a=10*(a%b),c--;);return a/b
      mov     ebx,  dword[esp+  12]
      mov     ecx,  dword[esp+  16]
      xor     eax,  eax
      dec     eax
      add     ecx,  2
      jc      .z
      cmp     ebx,  0
      je      .z            
      mov     eax,  dword[esp+  8]
.1:   xor     edx,  edx
      div     ebx
      dec     ecx
      jz      .z
      lea     eax,  [edx+edx*4]
      add     eax,  eax
      jmp     short  .1     ; a=5*a;a+=a=>a=10*a
.z:       
      pop     ebx
      ret     12
```
For parameter 'c' the range begin from 0; it would be 0..0xfffffffd. If parameters b=0 or c out of range 0..0xfffffffd it would return -1
[Answer]
# Lua, 42 bytes
```
function a(n,x,d)
print((n*10^x/d)%10)
end
```
[Answer]
# C, ~~49~~ 43 bytes
```
f(a,b,i){for(;a=10*(a%b),i--;);return a/b;}
```
'i' argument is 0-indexing. Test code and result
```
main()
{int i;
 for(i=0;i<20;++i)
     printf("%u", f(12,11,i));
 printf("\nf(1,2,3)=%d\n",f(1,2,3));
 printf("f(5,6,0)=%d\n",f(5,6,0));
 printf("f(5,6,1)=%d\n",f(5,6,1));
 printf("f(1,6,15)=%d\n",f(1,6,15));
 printf("f(1,11,2)=%d\n",f(1,11,2));
 printf("f(1,10000,9999999)=%d\n",f(1,10000,9999999));
 printf("f(11,7,1)=%d\n",f(11,7,1));
}
f(1,2,3)=0
f(5,6,0)=8
f(5,6,1)=3
f(1,6,15)=6
f(1,11,2)=0
f(1,10000,9999999)=0
f(11,7,1)=7 
```
[Answer]
# Java 7, ~~146~~ ~~139~~ ~~137~~ ~~133~~ ~~128~~ 122 Bytes
-3 bytes thanks to Erik the Outgolfer, I totally forgot imports didn't have to be on their own line
-4 bytes thanks to Qwerp-Derp for moving n%d to the constructor
-6 bytes thanks Kevin Cruijssen for removing the toString()
I hope this is how the byte count is done for java functions with imports
```
import java.math.*;char a(int n,int d,int x){return (new BigDecimal(n%d).divide(new BigDecimal(d),x+1,1)+"").charAt(x+2);}
```
Uses Java's BigDecimal class to get exact representation of the decimal expansion. Note it's not the fastest running code ever but it does eventually produce the correct output for all test cases. Ungolfed code:
```
import java.math.*;
char a(int n, int d, int x){
    BigDecimal num = new BigDecimal(n%d); // reduce improper fractions
    BigDecimal div = new BigDecimal(d);
    BigDecimal dec = num.divide(div, x+1, 1); // precision of x + 1, round down
    return (dec+"").charAt(x+2); //xth char after decimal
}
```
[Try it online!](https://tio.run/nexus/java-openjdk#jZDBasMwDIbPzVOIwsBejKk72h5CDxm77tTj2EGLTeoRO8F2soySZ8/s0l12aKaDBPq/XxLSpmtdgE8ckBsMZ/5YZFnXfzS6gqpB7@EVtb1kq1vPBwyxDK2WYKJCTsFpW7@9A7ra0wiukgFKOIJVX1c3oUVsn759UIa3feBdtITGkpIjEQy2DJ7oPWbHYM9g8w9G0IVdidktQSIdtQhtYtxKjPt45A@/101zdUYHSKIOlqUsr3mkF6dC7yyQ9LpnXb@oShtsiH2QlEs9aKn@SpKyMRdM0Hy9pjxNLgMZ8y0tpnmafwA)
[Answer]
## Clojure, 39 bytes
```
#(mod(int(/(*(Math/pow 10 %3)%)%2))10))
```
anonymous function with arguments `n,d,x` where `x` uses one based indexing.
[Answer]
# [F# (.NET Core)](https://www.microsoft.com/net/core/platform), 30 bytes
```
let f n d x=n*pown 10I x/d%10I
```
[Try it online!](https://tio.run/##TU5LCsIwFNz3FEOh0MoTTdVuSgRx5RnEhZqkFOSlNAGz6N1jbEFczAdmGMa49dOOOsaX9jBgKATJq8G@GWJ7QdioIukce@38@e60g8R1ElTTvj1QQ2LmuhVf3yQRgnbTLTN2RMkERQgVev4bUDYDhrFnbxh5kRoLII8oTvnyA6VB@ei71AJXP6uqNBfjBw "F# (.NET Core) – Try It Online")
(use 1-based indexing)
[Answer]
## Groovy, 30 bytes
```
{n,d,x->(n*10**x/d as int)%10}
```
x uses 1 based indexing. 
Explanation: 
```
{n,d,x->    // closure with three arguments, n, d, x
 n*10**x    // multiply n with 10 to the power of x
 /d         // divide by d
 as int     // convert from BigDecimal to int
 )%10       // modulo 10 to get the answer
}
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 6 bytes
```
/$›ḞṪt
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIvJOKAuuG4nuG5qnQiLCIiLCIyXG4xXG4zIl0=)
I do like the Sympy wrappers vyxal now has. Takes denominator, numerator then index.
## Explained
```
/$›ḞṪt
/      # divide the numerator by the denominator. This is fine because vyxal stores floats as Rationals internally. 
 $     # place the index at the top of the stack 
  ›Ḟ   # Sympy.evalf(fraction, n=index+1). This avoids rounding issues
    Ṫt # get the second last item  
```
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), 4 bytes (8 nibbles)
```
/\`p/*^~
```
Input is `x`, `n`, `d`. Uses 1-based indexing.
```
     *      # multiply
      ^~    #   10 to the power of
            #     (implicitly) arg1
            # by
            #   (implicitly) arg2
    /       # and divide this by (implicitly) arg3
  `p        # print the number as a string
 \          # reverse it
/           # and get the first element 
            # (by folding across it, each time
            # returning the left-hand of each pair)
```
[![enter image description here](https://i.stack.imgur.com/CaliH.png)](https://i.stack.imgur.com/CaliH.png)
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), 7 bytes
```
ᴇ*⇹/1ᴇ%
```
[Try it online!](https://tio.run/##K6gs@f//4ZZ2rUftO/UNgQzV//8NDbhMucwB "Pyt – Try It Online")
input is `x`,`n`,`d`
```
ᴇ         raises 10 to the x
 *        multiplies by n
  ⇹/      divides by d
    1ᴇ%   modulo 10; implicit print
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~50,44,40,~~ 36 bytes
```
lambda n,d,x:(`n*1./d%1`+'0'*x)[x+2]
```
[Try it online!](https://tio.run/nexus/python2#LYpBDoIwEEX3nGI2hhYmymDQhMSlp0ASUEpsgrXBGuvp60D9i3kvkzeeLmHqH9ehB4MD@lp0JqPtbthQl6dFmnnZ@Lxsg5u/dQKfu56UIMkKdtbGwSgybezbCSkT5W/KOjiv0E8D/QsUp7FUoSEscd8mTYUHLP4kJi2sViFuohS8eHnLi/DI9Q8 "Python 2 – TIO Nexus")
[Answer]
## Ruby, 39 bytes
```
->n,m,o{(n*1.0/m).to_s.split(?.)[1][o]}
```
[Answer]
# JavaScript (ES6), 34 bytes
```
(n,d,x)=>`${n/d}`.split`.`[1][x]|0
```
x is 0-based
```
f=
(n,d,x)=>`${n/d}`.split`.`[1][x]|0
console.log(f(1,2,3))
console.log(f(5,6,0))
console.log(f(5,6,1))
console.log(f(1,6,15))
console.log(f(1,11,2))
console.log(f(1,10000,10000000))
console.log(f(11,7,1))
console.log(f(2000,7,0))
```
[Answer]
# [Python 2](https://docs.python.org/2/), 32 bytes
Uses 0-indexing
```
lambda n,d,x:int(10**-~x*n/d)%10
```
[Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqiQp5OiU2GVmVeiYWigpaVbV6GVp5@iqWpo8D8tv0ghM68AiBWiNQx1jHSMNXU0THXMdAygtCGQNgTRpmCGIVANiGGoYw6VMjQAAghpYGCoGWvFxVlQBLQKZKyOQpqGFpDW/A8A "Python 2 – TIO Nexus")
Edit:
Rolled back to original solution as seen in Ørjan Johansen's answer that it works, but I won't golf it any further
[Answer]
# Groovy, 55 bytes
```
{n,d,x->z='0'*x;Eval.me("$n.$z/$d.$z").toString()[x-1]}
```
Explained using `1,11,2`:
```
{
    n,d,x->          // I've already lost to Jelly by the end of this line.
    z='0'*x;         // Set z equal to 2 0's.
    Eval.me          // Evaluate as groovy code...
    ("$n.$z/$d.$z")  // 1.00g/11.00g (Automatically set precision using # 0s).
   .toString()[x-1]  // Get 2nd digit of division.
}
```
[Answer]
# Axiom, ~~71 61~~ 76 bytes
```
f(a:NNI,b:PI,n:NNI):NNI==(repeat(a:=10*(a rem b);n=0=>break;n:=n-1);a quo b)
```
n is 0-indexing [0..M]. Test code and result
```
(19) ->    f(1,2,3)=0
   (19)  0= 0
(20) ->     f(5,6,0)=8
   (20)  8= 8
(21) ->     f(5,6,1)=3
   (21)  3= 3
(22) ->     f(1,6,15)=6
   (22)  6= 6
(23) ->     f(1,11,2)=0
   (23)  0= 0
(24) ->     f(1,10000,9999999)=0
   (24)  0= 0
(25) ->     f(11,7,1)=7
   (25)  7= 7
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 9 bytes
```
→d÷⁰*²!İ⁰
```
[Try it online!](https://tio.run/##yygtzv7//1HbpJTD2x81btA6tEnxyAYg4////4aG/83/GwEA "Husk – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 23 bytes
```
(a,b,i)=>a*10n**i/b%10n
```
[Try it online!](https://tio.run/##VYtBDoIwEEX3nGI2Ji1WaFFAa2DhgsQzYJMWJKQGC7GN18cCK/9i8vL@n5f6Ktt@9OQOZnx2c1XMSJGGaFyUKmTUhKGOm52H@RpIBgkcOdAghQwoh/MKjMMxYAukHDJPzO@WlSfqA5ctq2KQLw@5jOw0aCcfRkZvNSFXlMgWbrMoroGLGK/NTfd34zBpR2PHoYuGsUe1rakgtmbLSQSp0L/YM4M9nITAGM8/ "JavaScript (Node.js) – Try It Online")
---
# [JavaScript (Node.js)](https://nodejs.org), 43 bytes, [port](https://codegolf.stackexchange.com/a/118122/)
```
(a,b,i)=>eval(`for(;a=10*(a%b),i--;)a/b|0`)
```
[Try it online!](https://tio.run/##VYzNUoQwEITvPMVcLDMaINkf0VDZIy@BVGVY0MKKCUXinnx3DOzJPvT09Ex9X3SjcF2mOebOD@Pa6JUR7/mE@jLeyDLz4RdWk5biidFDj3zK8xqp7H@FwbXOjIQDHBWI7AwvIBS87kEqOGZyC2eVnDkfoeJAAab4GGBbF//jhnHA9CYTZEOkJJLg7a69klBttMoUYbZTNO/OFN80s6gvLOh4b1nZgupK3C8zLWFsrKeI/Opd8HYsrP9kbWhFx0MrNzt0vGH/i2eJaZ66DhHXPw "JavaScript (Node.js) – Try It Online")
# [JavaScript (Node.js)](https://nodejs.org), 51 bytes
```
(n,d,x)=>[...Array(x)].map(_=>[n*=10,u=n/d,n%=d])|u
```
[Try it online!](https://tio.run/##VY7BTsQgEIbvfYq5GBlFWnZdqxg28dKXQLIlS2NqKjRAzZr47hW6J//DzD/fTP7Mp/k28RzGOT04b4e1kytx1NILyqNijL2FYH7IBTX7MjM5ZejuJG/oIl1tqbuRVuPvsr5WPYcd7AU01QGeoBHwvBkuYF/xYg4iV@J8gpaCiTCm2whlDH5xdrCYz3gOKRHZNVnwctWGOLQlre1ZnKcx9e@u335K8kiiTFdKagVC17htZhPi0E3eJKRn76KfBjb5D6KiajSNipey07Qj/8E9x9wftUbE9Q8 "JavaScript (Node.js) – Try It Online")
use Array rather than recursive to avoid [stackoverflow](https://stackoverflow.com/)
[Answer]
# [Thunno](https://github.com/Thunno/Thunno), \$ 9 \log\_{256}(96) \approx \$ 7.41 bytes
```
10@*s10%,
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhYrDQ0ctIoNDVR1IPwFMMqQy5TLDMIBAA) Takes `x` then `n` then `d`.
Port of [Ørjan Johansen's Python answer](https://codegolf.stackexchange.com/a/117468/114446)
**Explanation:**
```
10@*s10%,  # Implicit input, x then n then d
10@        # 10**x
   *       # *n
    s      # Swap so d is on top
     10%   # d%10
        ,  # Integer divide
           # Implicit output
```
]