Use snprintf to format the string and then output it, so as to support more formats and reduce the footprint.