Two decimal points on form field calculations

When a calculation is done on a form field, especially for money values, it's often a requirement to use two decimal places. This can be done by adding some custom javascript that creates a money() function to a paragraph element and then wrapping your calculation in the money() function. 

Add this javascript to a paragraph element:

<script type="text/javascript">
function formatMoney(_number) {
var answer = Math.round(Number(_number) * 100) / 100;
answer += '';
if (answer.match(/.\d\d$/)) { return answer + ''; }
else if (answer.match(/.\d$/)) { return answer + '0'; }
else { return answer + '.00'; }
</script> <script src="https://secure.sitemason.com/.sm/scripts/sitemason.com/common.js" type="text/javascript"></script>


Next, wrap your calculation in the money() function, Ex:



The resulting total will then appear as two decimal places. 


Please sign in to leave a comment.