encode with string optimization for all numeric types