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.
Fixed
You are right,
Expected: 1.98, Result: 1.98
is a terrible error message.Also,
round(X * 100) * 0.01
is indeed a trap I did not think about.I have changed the test output from
to
Better?
Fixed
I can confirm I had the same issue in my solution, thanks for the tip!
If you think the tests are wrong, please post your solution (surrounded by a line with just three backticks (```) and marked as "having spoiler content") and the failed tests.
There are many values that cannot be represented exactly in IEEE-754 floating point numbers.
Instead the nearest representable value will be used. E.g.
9.45
is stored as9.44999999999999929
and9.46
is stored as9.46000000000000085
.The task asks for some value
v
, rounded to two decimal places (let's call itr
).The rounding makes the result unambiguous. You should return the nearest representable value to
r
.That's what is tested in JavaScript (
Test.assertEquals(actual, expected);
), C++ (Assert::That(actual, Equals(expected));
), Python (Test.assert_equals(actual, expected)
), etc.All that sound complicated but it's not. Compute
v
as exact as possible and then use the rounding functions of the programming language to obtainr
fromv
.Yep. It's easy to code once you know the answer, but you have to figure out the answer...
Thanks for your feedback. I wrote this originally in JavaScript and then trusted the translations after checking them to the best of my ability. Can someone fluent in C++ help with this? That seems to be the language that has had the most trouble with this kata.