Convert a Duration as a Decimal Number to ISO 8601 Duration Format

How to Use

XBRL facts representing periods of time are in the Data Type durationItemType which is entered in the 'PnYnMnDTnHnMnS' format also known as ISO 8601 Duration Format.
For example, the XBRL element DebtInstrumentTerm is defined “Period of time between issuance and maturity of debt instrument, in PnYnMnDTnHnMnS' format, for example, 'P1Y5M13D' represents the reported fact of one year, five months, and thirteen days.”

Typically these facts have been represented as decimal numbers. If the term is four years, the number entered in the financial statement by the accountant might be 4.0 which converts easily to P4Y.
Simple for any XBRL preparer. However, facts representing time remaining are more complicated.
For example, you might have “Weighted-Average Remaining Life in Years” (element SharebasedCompensationArrangementBySharebasedPaymentAwardOptionsOutstandingWeightedAverageRemainingContractualTerm2)
for some Stock Options, where it's some odd amount like 6 years and 18 days which the accountant has entered as 6.05.
How does one convert that to durationItemType? That's what this conversion program below does.