def serialize_num(val):
 if isinstance(val, bool):
  return str(int(val))
 return str(val)

def serialize_num ( val ) : if isinstance ( val , bool ) : return str ( int ( val ) ) return str ( val )
cast a number to a string and perform validation to ensure no loss of precision .