diff --git a/src/ruc/format/builder.cpp b/src/ruc/format/builder.cpp index 38caf38..ecf8146 100644 --- a/src/ruc/format/builder.cpp +++ b/src/ruc/format/builder.cpp @@ -189,12 +189,19 @@ void Builder::putF64(double number, uint8_t precision) const // There is no number behind the decimal point if (dot == std::string::npos) { if (precision > 0) { - converted += ".0"; + converted += '.' + std::string(precision, '0'); } m_builder << converted; return; } + // If there are less numbers behind the decimal point than the precision + if (converted.length() < length) { + converted += std::string(length - converted.length(), '0'); + m_builder << converted; + return; + } + // Only round if there are more numbers behind the decimal point than the precision, // or the number that comes after the maximum precision is higher than 4 if (converted.length() > length && converted[length] > '4') {