Factor our encode_decimal. Give it a test.