brewersfan1976

after_decimal_point.rb

Feb 27th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.68 KB | None | 0 0
  1. def quotientKthDigitAfterDecimalPoint(a, b, k)
  2.     a = a * 1.0
  3.     b = b * 1.0
  4.     number = (a / b)
  5.     string = number.to_s
  6.     string_length = string.length
  7.     result = 0
  8.     x = 0
  9.     y = 0
  10.    
  11.     if a % b == 0 then
  12.         return 0
  13.     end
  14.    
  15.     while (x < string_length)
  16.         if string[x] == "." then
  17.            
  18.            while (y <= k)
  19.                result = string[x]
  20.                x = x + 1
  21.                y = y + 1
  22.                
  23.                if y == 16 then
  24.                    break
  25.                end
  26.            end
  27.            
  28.            break
  29.         end
  30.            
  31.         x = x + 1
  32.     end
  33.        
  34.     return result.to_i
  35. end
Advertisement
Add Comment
Please, Sign In to add comment