mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 03:07:36 +02:00
Make floating-point formatting locale-independent
This commit is contained in:
@ -735,13 +735,17 @@ void sprintf_format(Double value, internal::buffer& buf,
|
|||||||
if (result >= 0) {
|
if (result >= 0) {
|
||||||
unsigned n = internal::to_unsigned(result);
|
unsigned n = internal::to_unsigned(result);
|
||||||
if (n < buf.capacity()) {
|
if (n < buf.capacity()) {
|
||||||
if (!spec.type) {
|
// Find the decimal point.
|
||||||
// Keep only one trailing zero after the decimal point.
|
auto p = buf.data(), end = p + n;
|
||||||
auto p = static_cast<char*>(std::memchr(buf.data(), '.', n));
|
if (*p == '+' || *p == '-') ++p;
|
||||||
if (p) {
|
if (spec.type == 'a' || spec.type == 'A') p += 2; // Skip "0x".
|
||||||
|
while (p < end && *p >= '0' && *p <= '9') ++p;
|
||||||
|
if (p < end && *p != 'e' && *p != 'E') {
|
||||||
|
if (*p != '.') *p = '.';
|
||||||
|
if (!spec.type) {
|
||||||
|
// Keep only one trailing zero after the decimal point.
|
||||||
++p;
|
++p;
|
||||||
if (*p == '0') ++p;
|
if (*p == '0') ++p;
|
||||||
const char* end = buf.data() + n;
|
|
||||||
while (p != end && *p >= '1' && *p <= '9') ++p;
|
while (p != end && *p >= '1' && *p <= '9') ++p;
|
||||||
char* where = p;
|
char* where = p;
|
||||||
while (p != end && *p == '0') ++p;
|
while (p != end && *p == '0') ++p;
|
||||||
|
Reference in New Issue
Block a user