Fix issue with parsing a scalar into thousands digits and hundreds digits

Use substr($y,-6,3) and substr($y,-3,3) to get the thousands digits and hundreds digits of numbers.