Last week in the Chandoo.org Forums a user asked a question
“How do I convert a Roman Numeral to a Number eg: MMMCCCLVII to 3357”
User Xlstime presented the solution of:
=MATCH(A2,INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0),0)
Today we are going to look at how and why that simple formula works
As always at Formula Forensics you can follow along using a sample file: Download Sample File
Solution
Excel has a Roman function wherein =Roman(3357, 0) will return MMMCCCLVII
I knew there was no such reverse Roman function prior to Excel 2013 and so my initial thought was to look at a VBA Solution.
See notes on the Arabic Excel function at the end of the post.
However Xlstime presented =MATCH(A2,INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0),0)
How does this work?
lets start by pulling it apart from the inside out
=MATCH(A2,INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0),0)
The Indirect Function simply takes its inputs and converts them to a Range, in this case 1:3999.
We will study why 3999 later
=MATCH(A2,INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0),0)
The next function working out is Row()
Excel will convert the function ROW(INDIRECT(“1:3999”)) to an array of Row Numbers
={1;2;3;4;5;6;7;8;9;10;11; …. 3995;3996;3997;3998;3999}
You can see this if you goto cell D7 in the Sample File, press F2 and then F9
I limited the numbers to 300 as Excel cannot display more than 8,192 digits
Stepping out one more function:
=MATCH(A2,INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0),0)
The Roman() function converts its inputs into Roman Numbers
eg: Roman(58) will return LVIII
But as we are feeding it an array of numbers from 1 to 3999 Excel handles all these and converts them to an Array of Roman Numbers
Goto D9 in the sample file =ROMAN(ROW(INDIRECT(“1:300”))) press F2 and then F9
Excel returns an array of roman numbers
={“I”;”II”;”III”;”IV”;”V”;”VI”;”VII”;”VIII”; … “CCXCVI”;”CCXCVII”;”CCXCVIII”;”CCXCIX”;”CCC”}
We have limited the example to 300 as Excel cannot display more than 8,192 characters when processing a Function using F9.
Stepping out one more function
=MATCH(A2,INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0),0)
The Excel Index() function is taking the Array of Roman Numerals and Converting it into a single Column array
This isn’t technically needed but it simplifies the solution
If you goto cell D11 in the sample file =INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0) press F2 and then F9
Excel returns an array of roman numbers
={“I”;”II”;”III”;”IV”;”V”;”VI”;”VII”;”VIII”; … “CCXCVI”;”CCXCVII”;”CCXCVIII”;”CCXCIX”;”CCC”}
This is exactly the same as the previous output from the Roman() function above, Except that it is now a Single Vertical Array. This is important for the next function.
Stepping out one more function
=MATCH(A2,INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0),0)
We can see here that the Array of Roman Numerals is now being fed into a Match() function.
Match uses the Syntax =Match(Lookup value, Lookup Array, Match Type)
Match returns the position of the Lookup value within the array
So in our example
The Lookup value is A2 or our Roman Numeral MMMCCCLVII
The Lookup Array is an array of Roman Numerals from 1 to 3999
={“I”;”II”;”III”;”IV”;”V”;”VI”;”VII”;”VIII”; … “MMMCMXCV”; “MMMCMXCVI”; “MMMCMXCVII”; “MMMCMXCVIII”; “MMMCMXCIX”}
and the Match Type is 0 or an exact Match
So the Match function will lookup the value MMMCCCLVII in the array and find it in position number 3357, which happens to correspond to the Number of the Roman Numeral and Return 3357 as the result.
Why are we limited to 3999 numbers.
The Excel Roman() function is limited to numbers up to 3999
Why 3999?
Because in Roman Numerals there is no Letter for 5,000 and 4,000 would be shown as M before the Letter for 5,000.
Why did we need the Index() function?
If you goto D17 in the sample file you will see the formula:
=MATCH(A2,ROMAN(ROW(INDIRECT(“1:3999”))),0)
It is the same formula as above but without the Index() function
You will see that it is returning a #VALUE! error
If you edit the formula with F2 and then press F9 to process the function you will see it now shows 3357
What s happening here?
Pressing F9 is the same as Array Entering the Function
so if you edit the function pressing F2 and now Array Enter the function by pressing Ctrl+Shift+Enter, excel now returns 3357
The Index() function puts a wrapper around the array for processing by the Match() function and so Array Entering is avoided.
Most array formulas that require Ctrl+Shift+Enter can be rewritten incorporating an INDEX wrapper and will not require the Ctrl+Shift+Enter confirmation.
The Excel Arabic Function
In 2013, Microsoft introduced the Arabic function to Excel
To use simply use =Arabic(A2) or =Arabic(“MMMCCCLVII”)
You can read about the Syntax of the function in the Excel Help.
Download
You can download a copy of the above file and follow along, Download Sample File.
A Challenge
Can you solve the problem another way ?
Post your solutions in the comments below.
Other Posts in this Series
The Formula Forensics Series contains a wealth of useful solutions and information specifically about how Normal Formula and specifically Array Formula work.
You can learn more about how to pull Excel Formulas apart in the following posts: http://chandoo.org/wp/formula-forensics-homepage/
If you have a formula and you want to understand how it works contact Hui and it may be featured in future posts.

















13 Responses to “Convert fractional Excel time to hours & minutes [Quick tip]”
Hi Purna..
Again a great tip.. Its a great way to convert Fractional Time..
By the way.. Excel has two great and rarely used formula..
=DOLLARFR(7.8,60) and =DOLLARDE(7.48,60)
basically US Account person uses those to convert some currency denomination.. and we can use it to convert Year(i.e 3.11 Year = 3 year 11 month) and Week(6.5 week = 6 week 5 days), in the same manner...
This doesn't work for me. When applying the custom format of [h]:mm to 7.8 I get 187:12
Any ideas why?
@Jason
7.8 in Excel talk means 7.8 days
=7.8*24
=187.2 Hrs
=187 Hrs 12 Mins
If you follow Chandoo's instructions you will see that he divides the 7.8 by 24 to get it to a fraction of a day
Simple, assuming the fractional time is in cell A1,
Use below steps to convert it to hours & minutes:
1. In the target cell, write =A1/24
2. Select the target cell and press CTRL+1 to format it (you can also right click and select format cells)
3. Select Custom from “Number” tab and enter the code [h]:mm
4. Done!
Hi, sorry to point this out but Column C Header is misspelt 'Hours Palyed'
good one
So how do I go the other way and get hours and minutes to fractional time?
If you have 7.5 in cell A1,
- Use int(A1) to get the hours.
- Use mod(A1,1)*60 to get minutes.
If you have 7:30 (formatted as time) in A1
- Use hours(a1) to get hours
- Use minutes(a1) to get minutes.
I had the same issue. You can solve it by changing the format as described above:
Right click cell > Format Cells > (In Number tab) > Custom > Then enter the code [h]:mm
([hh]:mm and [hhh]:mm are nice too if you want to show leading zeros)
Thanks guys, these are the tips I'm looking for.
...dividing the number of minutes elapsed by the percent change is my task - "int" is the key this time
It doesnt work for greater than 24 hours
It returns 1:30 for 25.5 hours. It should have returned 25:30
Ideally I would right function as
=QUOTIENT(A1,1)&":"&MOD(A1,1)*60
Sorry, replied to wrong comment....
----
I had the same issue. You can solve it by changing the format as described above:
Right click cell > Format Cells > (In Number tab) > Custom > Then enter the code [h]:mm
([hh]:mm and [hhh]:mm are nice too if you want to show leading zeros)
Clever use of MOD here to extract the decimal part of a number. Divide a number containing a decimal by 1 and return the remainder. Humm. Very clever.
Thanks very much, extremely useful !