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

Conversion from ratio to percentage gives strange results #61

Open
sergioisidoro opened this issue Apr 5, 2019 · 1 comment
Open

Conversion from ratio to percentage gives strange results #61

sergioisidoro opened this issue Apr 5, 2019 · 1 comment

Comments

@sergioisidoro
Copy link

sergioisidoro commented Apr 5, 2019

I have some numbers which are a ratios and is by definition unitless.

However I need to convert those ratios to percentages (multiply by 100), so I tried to "fake" the ratio unit by using 0.35 100%

 Unitwise(0.35, "100%").convert_to("%")
 => #<Unitwise::Measurement value=78812993478983675/2251799813685248 unit=%> 

This result happens to be correct,

78812993478983675 / 2251799813685248 = 35

But it's a quite inconvenient value.

This also happens if I try to create a unit for ratio

Unitwise.register(
  names: ["ratio"],
  symbol: ":",
  primary_code: "ratio",
  secondary_code: "ratio",
  scale: {
    value: 100,
    unit_code: '%'
  },
  property: 'ratio'
)

Unitwise(0.35, ":").convert_to("%").value
 => (78812993478983675/2251799813685248)

Of course it's just multiplying by 100, but in my case the situation is a bit more complicated with the internals of the work I'm making.

@sergioisidoro sergioisidoro changed the title Conversion from ration to percentage gives strange results Conversion from ratio to percentage gives strange results Apr 5, 2019
@sergioisidoro
Copy link
Author

Another issue found:

Unitwise(10, "mg/(24.h)").convert_to("g/(24.h)").to_f
0.0100000000224

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