Skip to main content
RC_Precast
Participant
May 22, 2017
Answered

Feet/Inches Calculation needing 2 decimal points

  • May 22, 2017
  • 1 reply
  • 1168 views

I have a formula that needs to calculate in Feet and Inches.  I have the formula working to calculate correctly, but now I need the inches to be only to 2 decimal points.  Please assist in how I get the inches to stop at 2 decimal points.  Thank you.

var PoleLenght = this.getField("PoleLenght").value;

if (PoleLenght>0)

{

var distanceInInches = (PoleLenght*0.162)+7.5;

event.value = convertInchesToFeet(distanceInInches);

}

else event.value = "";

function convertInchesToFeet(v)

{

var feet = Math.floor(v/12);

var inches = v%12;

return feet + "'-" + inches + "\"";

}

This topic has been closed for replies.
Correct answer RC_Precast

I figured it out.  I needed to add Math.floor for inches.

var inches = Math.floor ((v%12)* 100) / 100;

1 reply

Bernd Alheit
Community Expert
Community Expert
May 23, 2017

You can use the function Math.round()

RC_Precast
Participant
May 24, 2017

I need the inches to stop calculating after 2 decimals, not round to 2 decimals.

RC_Precast
RC_PrecastAuthorCorrect answer
Participant
May 24, 2017

I figured it out.  I needed to add Math.floor for inches.

var inches = Math.floor ((v%12)* 100) / 100;