Completed halfNumber function