PowerToys: Volume conversion doesn't work between imperial and metric

Microsoft PowerToys version

0.80.1

Installation method

PowerToys auto-update

Running as admin

Yes

Area(s) with issue?

PowerToys Run

Steps to reproduce

I attempted to convert from (fluid) ounces to milliliters, but was unable to do so. I tried several combinations like:

  • oz to ml
  • floz to ml
  • fl oz to ml
  • ounces to milliliters
  • fluid ounces to milliliters

It does not work with or without the activation command: image

image

It seems as though “ounces” and related abbreviations are reserved for weight, but they should be used for fluid volume as well.

I have confirmed that the plug-in is enabled: image

And I have also confirmed that other conversions work fine: image image

✔️ Expected Behavior

A conversion from (fluid) ounces to another unit. To minimize confusion, the output should expand an input of oz to fluid ounces, e.g.

%% 32 ml to oz 1.126243 fluid ounces copy volume to clipboard

Additionally, it might be helpful to reserve the oz abbreviation for weight, and require volume to be floz or fl oz.

❌ Actual Behavior

it is currently not possible to convert to or from fluid ounces.

Other Software

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 18 (5 by maintainers)

Commits related to this issue

Most upvoted comments

UnitsNet offers no capability for complex parsing or disambiguating, this would be up to each application as it stands today.

I would take a look at how others solve this: Google search: 32oz to ml image

Wolfram alpha: https://www.wolframalpha.com/input?i=32oz+to+ml image

For such cases we can generate two results. One for each type of ounces.

@angularsen sounds like this should be an issue in your repo?

So this may be much more complicated after all

Oh it sure is! The words “ounce” and “pound” are super ambiguous.

As for this issue, I defer to @htcfreek (for the plug-in) c.q. @angularsen (for the units)

Hi guys, this is my first time commenting here. I looked into the issue. And it seems like an issue with the underlying package - UnitsNet. Not an issue but the specified unit does not exist in the package. A simple fix could be to write a custom unit, let’s say “fluid ounce” represented by “floz”. In addition to that, we would also need to add conversions between different units. Upgrading would not help, since even in the latest version (5.50.0), there are no units associated with fluids. Please correct me if I’m wrong since it’s my first time here. References -

1. https://github.com/angularsen/UnitsNet/blob/UnitsNet/4.145.0/Common/UnitEnumValues.g.json

2. https://github.com/angularsen/UnitsNet/blob/master/Common/UnitEnumValues.g.json

3. https://github.com/angularsen/UnitsNet/tree/UnitsNet/4.145.0?tab=readme-ov-file#custom-units

Hey, thanks for investigating this! I didn’t even realize that this may be from an external package (but even if I did I still wouldn’t know how to fix it lol) Actually, it looks like the package does have it, in the Volume section:

"Volume": {
...
    "UsOunce": 48,
...
  },

And in fact, if I do something like 38 usounce to ml it works as expected: image What’s funny is I’ve never heard it specifically referred to as a “US ounce” but… That probably makes sense since I live in the US lol. I would have never thought to try this. @Jay-o-Way Is it possible to have multiple units with the same name? For instance, could we override/alias the package’s “usounce” to “ounce” and “oz” and then check if we’re doing volume or weight conversion? If we can’t do “ounce” and “oz” because of a collision, then maybe we could add “fluid ounce” and “floz” instead. This could present a potential issue if a user is trying to go from weight in ounces to volume, but the onus should be on the user to understand that you can’t directly translate from weight to volume with a simple converter like this. Alternatively, I didn’t look too closely at the package that this comes from. It’s possible that they already have something built that will handle this, or make it easier for us to implement. WDYT?

Hi @UltraKeelan, thanks for responding. I think that we could have a custom check in the GetUnitEnum function, which is basically like a converter for converting the string values to their enum counterparts. I wrote a simple if block for the same and it works!

image And below is the result -

image

It will now work for all kinds of input like 32oz, 32 floz, 32ounce, etc.

References -

1. https://github.com/microsoft/PowerToys/blob/59f978529666f9a0b22f574fc2949ce27c0898dc/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/UnitHandler.cs#L36

Oh nice! My only concern here is that oz and ounce won’t always be fluid ounce. With your example, what happens if you try to do a valid weight conversion like 32 oz to g? I’m also curious about what happens when you convert to ounces.

Hey @Jay-o-Way! My bad, I totally should have clarified that the plug-in is activated and otherwise works.

I updated my original post to include this info!