Your problem is in the "createCustomHTMLContent" function.
Floating point numbers (as 0.702 is) are not completely accurate in
Javascript (nor many other computer languages). They use some tricks for
speed, at the cost of resolution. As such, 0.702 cannot be represented
completed in floating point, so it's approximated as 0.7019999…
Most languages, include JS, provide mechanisms for this shortcoming. In
Javascript's case, it's the "toPrecision" function. What you want your
"createCustomHTMLContent" function to do is:
function createCustomHTMLContent(percentageY2007, percentageY2008,
percentageY2009, percentageY2010, percentageY2011, percentageY2012) {
return '2007: ' + (percentageY2007).toPrecision(3) + '% ' + '|' + '
2008: ' + (percentageY2008).toPrecision(3) + '% ' + '|' + ' 2009: ' +
(percentageY2009).toPrecision(3) + '% ' + '|' + ' 2010: ' +
(percentageY2010).toPrecision(3) + '% ' + '|' + ' 2011: ' +
(percentageY2011).toPrecision(3) + '% ' + '|' + ' 2012: ' +
(percentageY2012).toPrecision(3) + '%';
}
Here is a fiddle that shows this:
http://jsfiddle.net/XPArp/
Good luck.
On Tuesday, July 8, 2014 1:23:28 AM UTC-4, Nicole Goldup wrote:
>
> Hi there,
>
> I have two column charts that I have set the format as #%. I have a custom
> tooltip that the values are being multiplied by 100 (to show the percentage
> value instead of the decimal value). Some of the values have added extra
> decimal places than it should have.
>
> Example pages:
>
> http://www.hpvregister.org.au/research/coverage-data/hpv-vaccination-coverage-2007-12
>
> http://www.hpvregister.org.au/research/coverage-data/hpv-vaccination-coverage-2012
>
> In the second example, if you hover over SA you will see the tooltip as
> 70.19999999999999%, but the value was 0.702 and 0.702 * 100 is 70.2 not
> 70.19999999999999
>
> Why are some values coming up with long decimals? Is there any way to
> limit the number of decimal places?
>
> Thanks,
> Nicole
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.