PowerToys
PowerToys copied to clipboard
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:
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:
And I have also confirmed that other conversions work fine:
✔️ 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
Hello and thanks for your message. Just to check: is the plug-in activated and available in global search? Aside from that: what happens if you directly search via the "activation character"? (default %%
)
@htcfreek time to update the nuget (#31316)
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!
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 -
- https://github.com/angularsen/UnitsNet/blob/UnitsNet/4.145.0/Common/UnitEnumValues.g.json
- https://github.com/angularsen/UnitsNet/blob/master/Common/UnitEnumValues.g.json
- https://github.com/angularsen/UnitsNet/tree/UnitsNet/4.145.0?tab=readme-ov-file#custom-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:
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 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:
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!
And below is the result -
It will now work for all kinds of input like 32oz
, 32 floz
, 32ounce
, etc.
References -
- https://github.com/microsoft/PowerToys/blob/59f978529666f9a0b22f574fc2949ce27c0898dc/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/UnitHandler.cs#L36
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: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!
And below is the result -
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.
Wonder if this issue here should wait on #32572 and if there are new possibilities and units coming with the new version.
Hi @UltraKeelan and @htcfreek, thanks for your interest in the issue. I've done some more investigation and here are my findings.
- For @UltraKeelan's doubt, regarding the conversion between
oz to g
. It currently doesn't work. A nice solution could be to use units likefloz
andfl oz
for fluid ounce andoz
andounce
for the regular ounce (representing mass) [Screenshots attached]. Also, for the conversion to ounces, it won't matter, since we're doing parsing way before this step. And, I'm only overwriting the unit's name that is already parsed. - For @htcfreek's doubt, no this issue should not wait on #32572, since, even if we upgrade the UnitsNet version from
4.145.0
to5.50.0
, there are no additions of any other units relating to ounces. If you're talking about any other core functionality changes then I can't comment.
Some screenshots for reference -
- The code change
- Fluid ounces to other volume changes
- Ounces to other mass changes
- Other mass changes to ounces (mass)
References -
- https://github.com/angularsen/UnitsNet/blob/UnitsNet/4.145.0/Common/UnitEnumValues.g.json
- https://github.com/angularsen/UnitsNet/blob/master/Common/UnitEnumValues.g.json
@angularsen sounds like this should be an issue in your repo?
@Jay-o-Way Hi, it could be, but since there is some integration on PowerToys side parsing human input and calling into UnitsNet, it would be helpful to get a short summary of the feature request for UnitsNet specifically.
Input parsing in UnitsNet is very basic and can pretty much just parse its own ToString()
representations, such as 5.5 oz
.
It has some lookups of unit abbreviations, that could be used to determine that oz
refers to both Volume
and Mass
ounces, but it offers no functionality to parse "5.5 oz to g" or similar inputs, which I assume PowerToys is handling.
A couple of problems:
- There are 3 ounce units in UnitsNet,
Mass.Ounce "oz"
,Volume.UsOunce "oz (U.S.)"
andVolume.ImperialOunce "oz (imp.)"
. -
Mass.Parse("5 oz")
works, because there is only one mass unit with this abbreviation. But,Volume.Parse("5 oz")
would fail due to ambiguity betweenVolume.UsOunce
andVolume.ImperialOunce
, so we used different abbreviationsoz (U.S.)
andoz (imp.)
for these. - Trying to parse
5 oz to g
requires figuring out the context, thatMass
is the common quantity and thatoz
then refersMass.Ounce
. It is possible to build such a mapping and resolve this in a parser, but we have not made any efforts in this direction. If anyone is interested in trying to build this feature into UnitsNet, I'm happy to assist.
Here are the relevant unit definitions. Volume.UsOunce
{
"SingularName": "UsOunce",
"PluralName": "UsOunces",
"FromUnitToBaseFunc": "{x} * 2.957352956253760505068307980135e-5",
"FromBaseToUnitFunc": "{x} / 2.957352956253760505068307980135e-5",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "oz (U.S.)" ]
},
{
"Culture": "ru-RU",
"Abbreviations": [ "Американская унция" ]
}
]
},
"SingularName": "ImperialOunce",
"PluralName": "ImperialOunces",
"FromUnitToBaseFunc": "{x} * 2.8413062499962901241875439064617e-5",
"FromBaseToUnitFunc": "{x} / 2.8413062499962901241875439064617e-5",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "oz (imp.)" ]
},
{
"Culture": "ru-RU",
"Abbreviations": [ "Английская унция" ]
}
]
},
{
"SingularName": "Ounce",
"PluralName": "Ounces",
"BaseUnits": {
"M": "Ounce"
},
"FromUnitToBaseFunc": "{x} * 0.028349523125",
"FromBaseToUnitFunc": "{x} / 0.028349523125",
"XmlDocSummary": "The international avoirdupois ounce (abbreviated oz) is defined as exactly 28.349523125 g under the international yard and pound agreement of 1959, signed by the United States and countries of the Commonwealth of Nations. 16 oz make up an avoirdupois pound.",
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Ounce",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "oz" ]
},
{
"Culture": "zh-CN",
"Abbreviations": [ "盎司" ]
}
]
},
Huh, well that's great, today I learned the absolutely cursed knowledge that there are two "common" volume measurements called an ounce, it didn't even occur to me that the US ounce might differ from the Imperial ounce. So this may be much more complicated after all :(
@Jay-o-Way perhaps the solution here is to make a call about choosing which one (US or Imperial) to treat as an "oz" for volume measurements, and then implement a solution to check whether the user is trying to do volume or weight measurements, and convert appropriately? This might be a bit too biased of a call for @angularsen to make, but perhaps we can do it in PowerToys. That's a big ask, but the payoff would be super convenient for a lot of folks and foster more usage of the plugin (probably 😉).
I also realize that this could introduce some ambiguity, since the output of the conversion uses the same string that the user puts in. For instance, something like 38 l to ml
will give 38000 ml
. I think it could be useful to always state the full PluralName
(or SingularName
when the output is 1
exactly) regardless of user input. What do you think of that? If it sounds good, I can open a separate feature request (and perhaps look into opening a merge request if the solution is simple enough).
So this may be much more complicated after all
Oh it sure is! The words "ounce" and "pound" are super ambiguous.
- An imperial fluid ounce is defined in British law as 28.4130625 millilitres, a US customary fluid ounce is 29.57353 mL, and a US food labelling fluid ounce is 30 mL.
- Besides the currency (ַ£ Pound Sterling), there are/were about six (!) different definitions of the weight pound: https://upload.wikimedia.org/wikipedia/commons/0/0a/Comparison_of_pounds.svg
As for this issue, I defer to @htcfreek (for the plug-in) c.q. @angularsen (for the units)
Hi @Jay-o-Way, I still don't understand how the parsing will work? Like, if a user types 32oz to ml
. How will we determine which unit to use (British, US customary, or US food labeling)? Is it covered for @angularsen or us?
On a side note, the above discussions about the units have been super informative.
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
Wolfram alpha: https://www.wolframalpha.com/input?i=32oz+to+ml
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
Wolfram alpha: https://www.wolframalpha.com/input?i=32oz+to+ml
For such cases we can generate two results. One for each type of ounces.
For such cases we can generate two results. One for each type of ounces.
Sounds like a great plan! Just to make sure, this would cover both input and output, right?
For such cases we can generate two results. One for each type of ounces.
Sounds like a great plan! Just to make sure, this would cover both input and output, right?
Generally yes.
But the results are based on the user input. For example if you convert from ounces to an other unit you would get one result per ounces type (2 possible types = 2 results).
And the same will happen when converting to ounces (2 possible types = 2 results)..
@htcfreek Can you assign me this? I can open a draft PR and you can probably check for the logic in it.