Add support for '%' type to output floating point values as a

percentage.

This helps with compatibility with Python's format strings.
This commit is contained in:
gawain
2019-03-05 17:36:20 -08:00
committed by Victor Zverovich
parent 287eaab3b2
commit 79b79f329e
3 changed files with 45 additions and 8 deletions
+8 -3
View File
@@ -539,8 +539,7 @@ struct fixed_stop {
void on_exp(int exp) {
if (!fixed) return;
exp += exp10;
if (exp >= 0)
precision += exp;
if (exp >= 0) precision += exp;
}
bool operator()(char*, int& size, uint64_t remainder, uint64_t divisor,
@@ -656,7 +655,13 @@ void sprintf_format(Double value, internal::buffer& buf,
*format_ptr++ = '*';
}
if (std::is_same<Double, long double>::value) *format_ptr++ = 'L';
char type = spec.type ? spec.type : 'g';
char type = spec.type;
if (type == '%')
type = 'f';
else if (type == 0)
type = 'g';
#if FMT_MSC_VER
if (type == 'F') {
// MSVC's printf doesn't support 'F'.