How to round to hundredths? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

How to round to hundredths?

Input: a=3,141592 b=5,566 Output: a=3,14 b=5,57

30th Mar 2020, 4:58 PM
PUFFIN Channel
PUFFIN Channel - avatar
2 Answers
+ 2
Multiply by 100, rounddown, and then divide by 100. Include standard math library to use floor function
30th Mar 2020, 5:10 PM
Gordon - avatar
+ 2
The earliest way is to set precision std::precision(number of positions +1);
30th Mar 2020, 6:28 PM
BroFar - avatar