Fixed the bug to handle non-terminating decimal expansion