Remove duplication in number-handling code