Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use round instead of floor to ensure the hundreds place is correct #43381

Merged
merged 2 commits into from

2 participants

@petercollingridge
Collaborator

This should ensure that values in the hundredth place is correct and fix #41894.

@spicyj
Owner

you probably want to round before the %? not 100% sure.

@petercollingridge
Collaborator

OK - does is make much difference? I guess modulo arithmetic with decimals is a bit weird. It's mainly just an issue because of the floating point imprecision breaks 29, 57, and 58.

@spicyj
Owner

I would assume that round(9.999 % 10) gives 10 instead of 0…

@petercollingridge
Collaborator

Try (100 * (58 / 100)) % 10 - that's what caused the problem.

@spicyj
Owner

but supposing 100 * 0.10 was 9.999999 you'd run into a problem, yes?

@petercollingridge
Collaborator

If you use floor. If you use round, it works no?

@petercollingridge
Collaborator

Oh, I see what you mean - round first.

@spicyj
Owner

:)

@petercollingridge
Collaborator

It is neater that way too.

@spicyj
Owner

lgtm!

@petercollingridge petercollingridge merged commit 050dcce into from
@petercollingridge petercollingridge deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  exercises/converting_decimals_to_fractions_1.html
View
2  exercises/converting_decimals_to_fractions_1.html
@@ -25,7 +25,7 @@
<div class="vars">
<var id="D">randRangeExclude(1, 99, [10,20,30,40,50,60,70,80,90]) / 100</var>
<var id="T">floor( D * 10 )</var>
- <var id="H">floor( ( D * 100 ) % 10 )</var>
+ <var id="H">round( D * 100 ) % 10</var>
</div>
<p class="question">Express <code><var>D.toFixed( 2 )</var></code> as a fraction.</p>
<p class="solution" data-type="rational" data-simplify="optional"><var>D</var></p>
Something went wrong with that request. Please try again.