Permalink
Browse files

Use round instead of floor

Using floor breaks when D = 29, 57 or 58. See #41894
  • Loading branch information...
1 parent e396c47 commit 46b4324c9efc8a4027860b4de79eaae08b7bce49 @petercollingridge petercollingridge committed Mar 15, 2013
Showing with 1 addition and 1 deletion.
  1. +1 −1 exercises/converting_fractions_to_decimals.html
@@ -12,7 +12,7 @@
<div class="vars" data-ensure="getGCD( NUMERATOR, DENOMINATOR ) === 1">
<var id="NUMERATOR">randRange( 1, 30 )</var>
<var id="DENOMINATOR">randRange( NUMERATOR + 1, 30 )</var>
- <var id="DECIMAL_4">Math.floor( NUMERATOR / DENOMINATOR * 10000 ) / 10000</var>
+ <var id="DECIMAL_4">Math.round( NUMERATOR / DENOMINATOR * 10000 ) / 10000</var>
<var id="DECIMAL">roundTo( 3, NUMERATOR / DENOMINATOR )</var>
</div>
<p>Express the fraction as a decimal, rounded to the thousandth.</p>

3 comments on commit 46b4324

@petercollingridge
Member

Sorry, I committed that by mistake. It should be fine, but I actually meant it for converting_decimals_to_fractions.

Test plan: Check that Math.round( NUMERATOR / DENOMINATOR * 10000 ) / 10000 gives the right value for a range of values. Or write a loop to test them all.

Auditors: beneater, alpert

@spicyj
Member
spicyj commented on 46b4324 Mar 15, 2013

Unfortunately Auditors doesn't work unless you put it in the commit message. :)

This looks fine to me.

@petercollingridge
Member

I actually edited directly on Github - it didn't realise that was possible before and didn't realise it would actually commit it. I didn't mean to edit this exercise, but I suspect it could prevent a similar problem with floating point precision errors. NUMERATOR / DENOMINATOR * 10000 should be an integer, so I think round makes sense.

Please sign in to comment.