• ###### BobAllan123commented on "Formatting decimal places #0" kata

That is an excellent article for explaining the concept.

I really appreciate you taking the time to look that up and share it. high five! :)

• ###### Voilecommented on "Formatting decimal places #0" kata

Try this ;-)

https://docs.python.org/3/tutorial/floatingpoint.html#tut-fp-issues

Also it should be `5` is not divisible by `2`, corrected.

• ###### BobAllan123commented on "Formatting decimal places #0" kata

Thank you Voile for the reply, I'm really trying to wrap my head around this so I don't run into this problem twice.

I'm still confused, especially by the statement "2 is not divisible by 5". I'm not saying you are wrong, I just don't understand.

Could you please point me to a reference that explains this concept in greater detail? I've searched for an hour and can't find anything.

• ###### Voilecommented on "Formatting decimal places #0" kata

It's a natural phenomenom of floating point numbers because you cannot represent values with 2 decimal places exactly in floats (as `5` is not divisible by `2`).

The test for `2.675` should've never been in there in the first place. I've removed it from the sample tests. The actual tests never have it anyway so you can just submit as normal ;-)

• ###### Voileresolved an issue on "Formatting decimal places #0" kata

Fixed. For the record, sample test has always been free to change as it doesn't trigger a re-validation.

Also for `2.675` being rounded to `2.67`, it's intended because of floating point error. If you want to handle floating point error properly, use the proper tools like a `Decimal` type.

• ###### BobAllan123commented on "Formatting decimal places #0" kata

This comment is hidden because it contains spoiler information about the solution

• ###### usufructcommented on "Formatting decimal places #0" kata

This kata, for at least Python, is harder than an Eight.

• ###### DestyNovacommented on "Formatting decimal places #1" kata

The testcase expected/actual diff should give you some clues. I'm guessing that using `String.format` that way causes the number to be rounded, instead of truncated toward zero.

• ###### user1958379commented on "Formatting decimal places #1" kata

What's wrong with my code

public class Numbers
{
public static double twoDecimalPlaces(double number)
{
return Double.valueOf(String.format("%.2f", number));
}
}

But when I writes this
return (int)(number * 100) / 100.0
It works. Why?

• ###### Chrono79commented on "Formatting decimal places #0" kata

Python final tests are locked and can't be modified anymore. You can write a solution that passes the sample and the final tests if you want (it's possible).
Maybe that particular sample test could be removed to be consistent.

• ###### Chrono79commented on "Formatting decimal places #0" kata

`number_format` returns a string to start with, read what it does here: http://php.net/manual/en/function.number-format.php
There is a better suited function you should use in php (and in most languages).

• ###### bx3commented on "Formatting decimal places #0" kata

Some explain why this doesn't work for PHP?

function twoDecimalPlaces(\$n){
return number_format(\$n, 2);
}

• ###### vladimirov1created an issue for "Formatting decimal places #0" kata

Python sample test is wrong. Final solution accepted when sample test fails.

• ###### Adulcommented on "Formatting decimal places #0" kata

or maybe there is a problem with the test case .. try "attempt"

• ###### sogrcommented on "Formatting decimal places #0" kata

This kata ...omg wth... my mind was blown. I'm not sure 8kyu for it. After into a tests was adding some new rules - such as 2.675? there is no sense for .format(), round() and other methods.