### Rounding

You might not have noticed, or no one told you, but computers suck at math. Well more specifically they suck at rounding. I’ve been told JavaScript especially sucks at math, and one should avoid using it for Math. I guess that’s why Autodesk choose to use JavaScript to do the reporting within Civil 3D for the XSL type reports.

One such report is the Inverse_Report. You may notice that some of your bearings are slightly off. This is because of floating precision that computers use and the method Autodesk has chosen to round numbers. To fix this error we can use a common method to round the value to the correct number. To do this travel to the folder that holds the XSL reporting files:

C:\ProgramData\Autodesk\C3D 2012\enu\Data\Reports\xsl

Next open the General_Formating_JScript.xsl, if you are on my computer it will be on the top if you sort by Date modified (your results may vary). Once you open the file look for:

var anglePrec = 3;

If you want your bearings to be rounded to the nearest second change the value from 3 to 0. For any other rounding values, change it to the desired precision. Unsure why this wasn’t included in the Parcel settings within Civil 3D. This is just a diversion from the task at hand, otherwise known as padding.

Next scroll down until you reach this code snippet:

function formatAngleNumber(number)

{

var strFormatted;

strFormatted = number.toFixed(anglePrec);

return strFormatted;

}

Change the above code to the following:

function formatAngleNumber(number)

{

var strFormatted;

// strFormatted = number.toFixed(anglePrec);

strFormatted = Math.round(number * Math.pow(10, anglePrec)) / Math.pow(10, anglePrec);

return strFormatted;

}

The // comments out the original line of code. The next line makes the number large and then divides the resulting math by a large number to make it small again. By doing this we can hopefully eliminate the rounding issue.