Browse Source

Format: Fill float printing with '0's until the precision

master
Riyyi 4 months ago
parent
commit
243442a3b6
  1. 9
      src/ruc/format/builder.cpp

9
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') {

Loading…
Cancel
Save