0
Why Python “%.2f” is not equal to Java “%.2f”?
Hi! Code challenge Kaleidoscopes (easy) In Python all test passed successfully, but in Java one test fails. In both programs the algorithm is same and I use System.out.printf(“%.2f”, price) for Java (price is double) and print(“%.2f” % price) in Python. When I use BigDecimals in Java for all my calculations I have got interesting result: I didn’t find the RoundingMode that suits all test! Almost all test passed when I use HALF_EVEN but one. And this one pass when I use DOWN rounding. Why?
9 ответов
+ 6
HNNX 🐿, honestly spoken:
I'm quite sure they didn't *plan* to trigger specific language intricacies. Surely it's just an accident.
They wanted their new code coach feature and in many ways didn't think it through.
You'll find several reports of users where it becomes quite obvious that the test cases are just sloppily designed.
+ 3
I am guessing a bit here, but different languages seem to use slightly different rounding algos and get to different results.
That came up in that paint cost code coach task before.
May there be a relation?
https://www.sololearn.com/discuss/2104980/?ref=app
+ 2
I haven't done any manual rounding in my C version. I just output it with .2lf (implicit rounding) and it worked just fine.
+ 2
Crazy. 🤨
They should really design their tasks and the tests in a way that they're unambiguous.
+ 1
I haven't noticed anyone complaining this in java this might help:
https://www.sololearn.com/Discuss/2135726/?ref=app
//I have not attempted in java if you could tell me test nos of failing tests
edit
Jegors Čemisovs take a look in the link of diago's post
+ 1
I writed the program that compare the correct calculation with sololearn calculation. The function small() is SoloLearn and big() is correct calculation.
https://github.com/rabestro/sololearn-challenges/blob/master/easy/pro-kaleidoscopes/KaleidoscopesDifference.java
And there is printed result for different values:
https://github.com/rabestro/sololearn-challenges/blob/master/easy/pro-kaleidoscopes/KaleidoscopesDifference.txt
+ 1
If I use incorrect calculation my programm pases all tests.
+ 1
HonFu I've been following that thread of yours for some time now and really think they should reconsider "beginner" challenges which don't deal with logic but specific language intricacies.
I struggled with rounding challenges because it worked on paper, the solution was right - I've even had test cases fail and succeed while running the same code twice.
0
What is array?