From c30686ebce24245faa5a2c531bb195dc79063790 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 5 Apr 2023 16:04:28 +0200 Subject: [PATCH] Fix logic to remove trailing zeros --- include/boost/charconv/to_chars.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/boost/charconv/to_chars.hpp b/include/boost/charconv/to_chars.hpp index a0f34d8..c5820c9 100644 --- a/include/boost/charconv/to_chars.hpp +++ b/include/boost/charconv/to_chars.hpp @@ -565,10 +565,14 @@ to_chars_result to_chars_hex(char* first, char* last, Real value, int precision) { break; } - else if (remaining_bits == 0 && precision != -1) // Do not print trailing zeros with unspecified precision + else if (remaining_bits == 0) { - std::memset(first, '0', static_cast(real_precision)); - first += real_precision; + // Do not print trailing zeros with unspecified precision + if (precision != -1) + { + std::memset(first, '0', static_cast(real_precision)); + first += real_precision; + } break; }