0
Rounded float in Kaleidoscope challenge
Hey there. I almost finished the Kaleidoscope challenge, which wasn‘t too difficult but I still run into the following issue (see code). Any tips on how I can adequately round to two decimal places to conclude the challenge? :) https://code.sololearn.com/c3FzGQY6783q/?ref=app
4 Respuestas
+ 3
Because programming language implements Banker's Rounding, to solve real world issue; While you need a Maths rounding, rounding up for all occurrences of 0.05
https://en.m.wikipedia.org/wiki/Rounding#Rounding_functions_in_programming_languages
Try defining your own rounding function by checking the hundredth digit.
+ 3
use setprecision
http://www.cplusplus.com/reference/iomanip/setprecision/
0
Thank you. I will try that.
0
It finally worked with << fixed << setprecision... But I encountered a totally new weird thing concerning rounded decimals. In this case I tried the following numbers: 3.345 and 3.445. The first number rounded up to 3.35 the second did not but became 3.44. How come?