Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way of combining guessing and limiting? #5

Open
Nkburdick opened this issue Nov 15, 2013 · 0 comments
Open

Is there a way of combining guessing and limiting? #5

Nkburdick opened this issue Nov 15, 2013 · 0 comments

Comments

@Nkburdick
Copy link

Great work on the gem, the parsing is excellent!

I'm wondering if I'm just missing it, so please let me know. I'd like to be able to have the number get as close as possible to what the user expects, such as 0.3333 resolving to 1/3, but then to have it also round to the nearest 1/8th or 1/16th if the guesswork didn't pan out. For example:

# Have 0.3333 return 1/3
Fractional.round_to_nearest_fraction(0.333333, "1/8").to_s(mixed_number:true) 
#=> "3/8"    Could this return "1/3"?

# But still have 
Fractional.round_to_nearest_fraction(1100.142857142857143, "1/16").to_s(mixed_number:true)
#=> "1100 1/8"  Which works great
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant