0
how to round a float point value in c++ ?? like c programme i can use %.2f for two value after decimal point.
5 ответов
+ 2
Aliul Nadab ,
you ca do this in c++ by using printf(...):
....
double d = 3.149;
printf("Double value: %.2f", d);
....
+ 2
Include <iomanip> header file and use std::setprecision(digits) in std::cout. You may also want to add std::fixed if the float becomes scientific notation
Example:
std::cout << setprecision(4) << 10.3428;
//output: 10.34
0
Lothar why should i use printf function...in c++..we are learning c++ and here is some different we have to keep the syntax remaining for c++ either their will be no different between c and c++.
0
CarrieForle i just want <iostream> header file using this how can i do?
0
Aliul Nadab Then you gotta make one yourself. I don't think there's a good reason to stick with iostream though.