Digit limitation from decimal point in C++
Are you actually trying to round the number, or just change its displayed precision? For the former (truncating the extra digits): or (rounding up/down as appropriate, per jheriko’s answer) For the latter: where the parameter to setprecision() is the maximum number of digits to show after the decimal point.