0

how to round a float point value in c++ ?? like c programme i can use %.2f for two value after decimal point.

25th Oct 2021, 1:41 PM
Aliul Nadab
Aliul Nadab - avatar
5 Respuestas
+ 2
Aliul Nadab , you ca do this in c++ by using printf(...): .... double d = 3.149; printf("Double value: %.2f", d); ....
25th Oct 2021, 1:59 PM
Lothar
Lothar - avatar
+ 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
25th Oct 2021, 2:08 PM
你知道規則,我也是
你知道規則,我也是 - avatar
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++.
25th Oct 2021, 6:53 PM
Aliul Nadab
Aliul Nadab - avatar
0
CarrieForle i just want <iostream> header file using this how can i do?
25th Oct 2021, 6:55 PM
Aliul Nadab
Aliul Nadab - avatar
0
Aliul Nadab Then you gotta make one yourself. I don't think there's a good reason to stick with iostream though.
25th Oct 2021, 10:54 PM
你知道規則,我也是
你知道規則,我也是 - avatar