Decimal Digit Truncating

Python 2, 103 101 98 94 93 87 bytes

a,b=input().split('.');i,w=0,len(b)
while w>i:w=min(int(b[i]),w);i+=1
print a+'.'+b[:w]

Try it online!


Saved:

  • -2 bytes, thanks to Kevin Cruijssen
  • -3 bytes, thanks to Vedant Kandoi
  • -4 bytes, thanks to Lynn

05AB1E, 18 bytes

2 bytes extra due to a bug with £ not handling 0 correctly.

'.¡`DvÐgsNè-F¨]'.ý

Try it online! or as a Test Suite

Explanation

    '.¡                 # split input on "."
       `                # push int and decimals separately to stack
        D               # duplicate decimal digits
         v              # for each
          Ð             # triplicate the current decimal digits
           g            # get the length
            sNè         # get the Nth digit
               -        # subtract from the total length
                F¨]     # drop that many digits from the end
                        # end loop
                   '.ý  # join on "."

JavaScript (Node.js), 58 bytes

f=(s,p=1/0,q=1,c=s[q])=>c?f(s.slice(0,p-~c),++c?p:q,q+1):s

Try it online!