Skip to content

# Khan/khan-exercises

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Loading…

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

Merged
merged 2 commits into from
+1 −1 

### 2 participants

Collaborator

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

 petercollingridge `Use round instead of floor to ensure the hundreds place is correct` `1f57ad4`
Owner

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

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.

Owner

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

Collaborator

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

Owner

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

Collaborator

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

Collaborator

Oh, I see what you mean - round first.

Owner

:)

 petercollingridge `Round before modulo` `eb8034f`
Collaborator

It is neater that way too.

Owner

lgtm!

merged commit `050dcce` into from
deleted the branch
to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 15, 2013
1. petercollingridge authored
2. petercollingridge authored
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
2  exercises/converting_decimals_to_fractions_1.html
 @@ -25,7 +25,7 @@
randRangeExclude(1, 99, [10,20,30,40,50,60,70,80,90]) / 100 floor( D * 10 ) - floor( ( D * 100 ) % 10 ) + round( D * 100 ) % 10

Express D.toFixed( 2 ) as a fraction.

D

Something went wrong with that request. Please try again.