Rounding results in highcharts jquery script Rounding results in highcharts jquery script jquery jquery

Rounding results in highcharts jquery script


In in the tooltip option in the configuration object use Math.round() in the formatter function.

   tooltip: {     formatter: function() {        return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' %';     }  },


There's a numberFormatfunction available in the Highcharts API that you can use (see http://www.highcharts.com/ref/#highcharts-object).

Quoted from API doc:

numberFormat (Number number, [Number decimals], [String decimalPoint], [String thousandsSep]) : String

Formats a JavaScript number with grouped thousands, a fixed amount of decimals and an optional decimal point. It is a port of PHP's function with the same name. See PHP number_format for a full explanation of the parameters.

tooltip: {    formatter: function() {        return ''+ this.series.name +''+            this.x +': '+ Highcharts.numberFormat(this.y, 0, ',') +' millions';    }}, ...

Parameters

  • number: NumberThe raw number to format.
  • decimals: NumberThe desired number of decimals.
  • decimalPoint: StringThe decimal point. Defaults to "." or to the string specified globally in options.lang.decimalPoint.
  • thousandsSep: StringThe thousands separator. Defaults to "," or to the string specified globally in options.lang.thousandsSep.

Returns

A string with with the input number formatted.