Rounded float in Kaleidoscope challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

29th Jun 2020, 7:40 AM
The_Fox
The_Fox - avatar
4 Answers
+ 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.
29th Jun 2020, 8:02 AM
Gordon
Gordon - avatar
29th Jun 2020, 8:17 AM
Bobby Fischer
Bobby Fischer - avatar
0
Thank you. I will try that.
29th Jun 2020, 8:07 AM
The_Fox
The_Fox - avatar
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?
29th Jun 2020, 9:09 AM
The_Fox
The_Fox - avatar