Aidan Garnish

Collaboration Not Competition

Using JQuery to round averages in a SharePoint view

I had a question from a user asking whether it was possible to round the Average that is displayed on SharePoint views to 2.d.p.

Out of the box this is not possible but with a little bit of JQuery we can find the average and round it to the required d.p.

<script src="jquery.js"></script>
<script>
$(document).ready(function(){
   $('b').each(function(index){
   var value = $(this).html();
   var num = value.replace('Average = ','');
   var result = Math.round(num*Math.pow(10,2))/Math.pow(10,2);
   $(this).replaceWith('<b>Average = '+result+'</b>');
   });
});
</script>

Comments are closed