Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Float
- def to_s( base = 2, maxdigitafterpoint = 10 )
- integer = truncate
- res = integer.to_s( base ) + "."
- i = 0
- fraction = self - integer
- while i < maxdigitafterpoint and fraction != 0.0
- fraction *= base
- digit = fraction.truncate
- res += digit.to_s
- fraction -= digit
- ++i
- end
- res
- end
- end
- puts 103.625.to_s
- puts 103.626.to_s(2,80)
Add Comment
Please, Sign In to add comment