Can anyone help me rewrite this code to round a decimal down to the full inch?

wagmanm

Board Regular
Joined
Feb 26, 2013
Messages
144
I use this to round decimals to all different size fractions but now I would like to have results that are only to a full inch. How can I make this round to a full inch, if possible to set limits I would like it to round down unless it is above x.85?
Code:
Public Function LenText2(FeetIn As Double)
 ' This function will change a decimal number of feet to the text string
 ' representation of feet, inches, and fractional inches.
 ' It will round the fractional inches to the nearest 1/x where x is the denominator.
 ' Copyright 1999 MrExcel.com
 Denominator = 2 ' must be 2, 4, 8, 16, 32, 64, 128, etc.
 NbrFeet = Fix(FeetIn)
 InchIn = (FeetIn - NbrFeet) * 12
 NbrInches = Fix(InchIn)
 FracIn = (InchIn - NbrInches) * Denominator
 Numerator = Application.WorksheetFunction.Round(FracIn, 0)
 If Numerator = 0 Then
 FracText = ""
 ElseIf InchIn >= (11 + (1.499999 / 2)) Then
 NbrFeet = NbrFeet + 1
 NbrInches = 0
 FracText = ""
 ElseIf Numerator = Denominator Then
 NbrInches = NbrInches + 1
 FracText = ""
Else
 Do
 ' If the numerator is even, divide both numerator and divisor by 2
 If Numerator = Application.WorksheetFunction.Even(Numerator) Then
 Numerator = Numerator / 2
 Denominator = Denominator / 2
 Else
 FracText = " " & Numerator & "/" & Denominator
 Exit Do
 End If
 Loop
End If
 LenText2 = NbrFeet & "' - " & NbrInches & FracText & """"
 End Function
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,216,129
Messages
6,129,046
Members
449,482
Latest member
al mugheen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top