# Is there a build-in function converting a quantity to one with mixed units (such as feet and inches)?

For example, I want to convert 179 centimeters into 5 feet and 10.4724 inches instead of 70.4724 inches (as this website did). Maybe in the future I would need to convert days to {years, months, days} combination, degrees to {degrees, minutes, seconds}, etc. I can indeed write some codes to perform the task, but after all personal codes are full of flaws and lack of exception handling, so I am looking for a built-in function.

• Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. Commented Jan 20, 2015 at 23:57
• In WolframAlpha (or Mathematica after "==") just type "179 centimeters in English units". There are built-in functions for time in Mathematica, however, such as FromDate[], all well documented. Commented Jan 21, 2015 at 0:06
• @DavidG.Stork Yes, $DateList[{y,m,d,h,m,s}]$ can solve some of the problems concerning time, but it has many restrictions: {y,m,d} cannot be 0; cannot display 3.14 days, but 3 days 3 hours 21 minutes 36 seconds instead. Commented Jan 21, 2015 at 0:27
• Could you please give one very specific example of the kind of problem you want solved? The conversion of days to {years, months, days} is straightforward. What else? Commented Jan 21, 2015 at 0:29
• @DavidG.Stork it is interesting that these are called English units. I wondered what W|A would tell me for "32 hogsheads + 9 pints + 17 gills in French units". It replied that this is $2.062\times10^{11}$ cubic Frenches. You learn something new every day. Oh, and it also thinks that this is a measure of engine displacement, although the French gauge system is used to describe the diameter of catheters. Commented Jan 21, 2015 at 0:33

UnitConvert[Quantity[179., "Centimeters"], MixedRadix["Feet", "Inches"]]


returns

Quantity[MixedRadix[5, 10.472440944881885], MixedRadix["Feet", "Inches"]]


which formats as 5'10.4724"

• +1 It is a very nice undocumented feature! Commented Jan 21, 2015 at 2:34
• @ybeltukov I actually didn't know this was undocumented; searching in the documentation center gets no results (!!!) but I'm sure I read this in the documentation center somewhere. Commented Jan 21, 2015 at 2:37
• Is there an undocumented Tag? This is not the first example. Reasonable to expect WRI at some point may mine this site. Commented Jan 21, 2015 at 4:21
• @alancalvitti undocumented tag added. Commented Jan 21, 2015 at 4:22
• @george2079 UnitConvert[Quantity["Meter"], MixedRadix["Feet", "Inches", "Inches"]] becomes 3'3"47/127". Not power-of-two fractions though. Commented Jan 23, 2015 at 23:40

There is no such build-in function. However, one can write it easily

convert[q_Quantity, units_List] := MapAt[{Total@#} &, #, -1][[2 ;;, 1]] &@
FoldList[Through@{IntegerPart, FractionalPart}[Last@#/#2] #2 &,
{q, q}, Reverse@Sort[Quantity /@ units]]

convert[Quantity[179., "Centimeters"], {"Feets", "Inches"}]
(* {Quantity[5, "Feet"], Quantity[10.4724, "Inches"]} *)

convert[Quantity[1.2345, "Meter"], {"Millimeters", "Centimeters"}]
(*{Quantity[123, "Centimeters"], Quantity[4.5, "Millimeters"]}*)

convert[Quantity[1.2345, "Degree"], {"Degree", "ArcMinute", "ArcSecond"}]
(*{Quantity[1, "AngularDegrees"], Quantity[14, "ArcMinutes"], Quantity[4.2, "ArcSeconds"]}*)


10.4 introduces MixedMagnitude and MixedUnit, eg:

Quantity[MixedMagnitude[{1/2, 2, 3}],
MixedUnit[{"Hours", "Minutes", "Seconds"}]]
`

which btw, renders with bogus DisplayForm

0 h 32 min 3 s

And try all 0's.