Now one by print digits after dot using school division method .
for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) { echo $ d ; $ x = $ x - ( $ y * $ d ) ; if ( $ x == 0 ) break ; $ x = $ x * 10 ; $ d = $ x / $ y ; if ( $ i == 0 ) echo " . " ; } }