You can use std::fixed and std::setprecision from the iomanip header:
#include <iostream> #include <iomanip> int main(void) { double d = 1.0 / 2; std::cout << std::fixed << std::setprecision(2) << d << std::endl; return 0; }
This prints 0.50 as desired.
paxdiablo
source share