Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
My directions already stated, "Your job is to return the best starting mark in meters, rounded to two decimal places." I don't know of any katas on Codewars that expect you to round earlier in the process of solving the problem. It should be rather obvious that any imprecision resulting from such early rounding could be compounded in the final result. So unless you find an explicit exception to this rule, you should assume that the rounding always occurs at the end.
I don't set the difficulty level of my own kata. That is determined by other people, who apparently didn't find this one sufficiently challenging to rank it higher.
Please don't enter "issues" on kata when the problem lies in your own lack of knowledge, ineffective solution, or failure to read the instructions. It is not appreciated here, as you will note in many of the forums. In this situation, marking your comment as a "question" would have been the appropriate alternative.
In any event, I am glad that you learned something along the way.
This comment is hidden because it contains spoiler information about the solution
C#
double
s represent IEEE 754 64 bit floating point values (see .NET documentation).Some values are not representable by
double
, like 0.33 (which is stored as 0.33000000000000002) or 9.45 (which is stored as 9.4499999999999993).Math.Round(x, 2)
multipliesx
by 100, and then determines whether the remaining fractional portion of the value is greater than or equal to 0.5 (see Math.Round documentation).If you calculate with values that differ slightly from the "real" values those difference might grow. E.g.
1.235 * 4.565 == 5.637775
, rounded to two decimal digits is5.64
. But if you round first you get1.24 * 4.57 == 5.6668
, rounded to two decimal digits is 5.67. The difference between the two multiplicants and their rounded counterparts is smaller than 0.01 but the products differ by 0.03.Generally speaking, use the highest precision available and only round at the end (if you have to).
General advice:
What language are you using to solve it? Some of the problems reported previously have been specific to certain languages, so I'd like to determine whether that is also the case here.