Reputation: 63
I'm using the code of demo pie-basic (Fiddle) with the following values :
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 34],
['IE', 33],
['Safari', 26],
['Opera', 7],
]
}]
and the problem is that it appears as 7.000000000000001%
instead of 7%
.
How can I get a rounded value to appear?
Upvotes: 6
Views: 179
Reputation: 168685
Well, I can't tell you how to prevent the floating point error from occurring in the first place, but I can tell you how to hide it from the user.
You can simply use Math.round()
in your formatter
function, as follows:
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' %';
}
You already have a formatter function; I've just added Math.round()
to it.
I've updated your fiddle to demonstrate: http://jsfiddle.net/A2cVe/1/
[EDIT] You mention that the tooltip was also showing the error. There is also a separate formatter
function for that. I've updated the fiddle again with both formatter functions now edited to show the expected value: http://jsfiddle.net/A2cVe/2/
Upvotes: 2
Reputation: 37578
This issue is related with known bug https://github.com/highslide-software/highcharts.com/issues/897
Upvotes: 0