Refactored getAsInteger and getAsDouble so it always returns a number if
the held object is an Integer or Double.