Not sure whether this can help you, but you can actually print an mpf_class
object and use I/O manipulators on it as a typical float
object.
Here is my code
#include <gmpxx.h>
#include <iostream>
#include <iomanip>
int main(void) {
mpf_class a;
a = 3141592653589793.2;
std::cout << a << std::endl;
// Outputs 3.14159e+15
std::cout << std::uppercase << std::showpos << std::setprecision(3) << a << std::endl;
// Outputs +3.14E+15
}
Then you can use an std::ostringstream
object instead of std::cout
.
Reference: https://gmplib.org/manual/C_002b_002b-Formatted-Output.html