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

Strange Conversion? #102

Closed
tsaiid opened this issue Jun 17, 2014 · 3 comments
Closed

Strange Conversion? #102

tsaiid opened this issue Jun 17, 2014 · 3 comments
Milestone

Comments

@tsaiid
Copy link

tsaiid commented Jun 17, 2014

ruby (2.1.2)
ruby-units (1.4.5)

2.1.2 :019 > Unit("1 mm") >> 'cm'
 => 1/10 cm
2.1.2 :020 > Unit("1.0 mm") >> 'cm'
 => 1/10 cm
2.1.2 :021 > Unit("1.1 mm") >> 'cm'
 => 0.11 cm
2.1.2 :022 > Unit("11 mm") >> 'cm'
 => 11/10 cm
2.1.2 :023 > Unit("111 mm") >> 'cm'
 => 111/10 cm

The result sometimes became rational. How can I force it not to be rational?

@olbrich
Copy link
Owner

olbrich commented Jun 18, 2014

the version you are using uses rational numbers internally to avoid rounding problems. Why do you want to force it to not be a rational?

@TheRealNeil
Copy link

I have the same issue.

2.0.0p247 :030 > unit = Unit('1 oz') >> 'g'
=> 45359237/1600000 g

I would much rather get 28.3495231 g (at least for decimal units).

2.0.0p247 :040 > unit.scalar.to_f
=> 28.349523125

Any thoughts?

@TheRealNeil
Copy link

I am also seeing

2.0.0p247 :058 > Unit.new('1 1/2 oz')
=> 3/2 oz

Correct but now very user friendly, can you offer me any advise?

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

3 participants