Round up to nearest cent | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Round up to nearest cent

How do you round up to the nearest cent in C++?

25th Apr 2021, 10:41 PM
Benjamin Rios
Benjamin Rios - avatar
1 Answer
+ 2
If you want to round a float to the nearest integer, you could use c++'s round function: ceil is a function that always rounds up. If you want to round to the nearest 2 digits, you could do something like: double x = 3.14159265358979; double rounded = round(x * 100) / 100.0; cout << rounded << endl; If you just need to print out the value, look at setprecision. An example is at:
25th Apr 2021, 10:56 PM
Josh Greig
Josh Greig - avatar