change decimal to feet and inches
On Fri, 22 Feb 2008 15:01:25 -0500, "James Silverton"
wrote:
Gary''s wrote on Fri, 22 Feb 2008 11:22:01 -0800:
GsS =INT(A1)&"' "&INT(12*(A1-INT(A1)))&"""
GsS "&TEXT(MOD(12*(A1-INT(A1)),1),"##/##")
Having once had the capability available to use recursion and
temporary variables in a formula (MLAB by Gary Knott), I still
miss it in Excel. I guess it is possible in a macro. It always
seems inelegant to have to calculate something more than once,
like (A1-INT(A1) ). It probably doesn't really make all that
much difference in speed.
James Silverton
Potomac, Maryland
E-mail, with obvious alterations:
not.jim.silverton.at.verizon.not
Well, here's a VBA version:
================================
Option Explicit
Function FtIn(n As Double, Optional Rnd) As Variant
'Rnd is an optional fractional denominator rounding
'in the range of 1-99
Dim dFt As Double
Dim dIn As Double
Dim Fmt As String
dFt = Int(n)
dIn = (n - dFt) * 12
If Not IsMissing(Rnd) Then
If Rnd < 1 Or Rnd 99 Then
FtIn = CVErr(xlErrNum)
Exit Function
End If
dIn = Round(dIn * Rnd, 0) / Rnd
End If
Fmt = IIf(dIn = Int(dIn), "#0\'", "#0 ?/??\'")
FtIn = dFt & "'--" & WorksheetFunction.Text(dIn, Fmt)
End Function
==============================
--ron
|