Simplify numeric parsing

An adaptation of a patch by Nathan Howell.

Signed-off-by: Pekka Enberg <penberg@iki.fi>