Convert double to string with fixed point notation, no trailing zeroes and witout sprintf
This question has been asked a couple of times, but all the answers either refer to sprintf or involve deleting the trailing zeroes manually. Is there really no better way? is it not possible to achieve this with std::stringstream ? First you calculate how many potential digits you have before and after the decimal: int digits_before = 1 + (int)floor(log10(fabs(value))); int digits_after = std::numeric_limits<double>::digits10 - digits_before; Then you find out how many of those digits are zeros: double whole = floor(pow(10, digits_after) * fabs(value) + 0.5); while (digits_after > 0 && (whole