MGS_Sebastien

Negative rounding doesn't give the good number

Recommended Posts

Hi,

I found a bug in FC, when you're setting : decimals: "0" and you have negative values in your graph, the value is not well rounded.

In example : -3.5 should be rounded at -4, currently it show -3. I think this is because your devs are using the Math.round integrated function of JS, but this is something wrong.

Try this dataSource :

const chartData = {
  chart: {
    caption: "Test decimals",
    theme: "fusion",
    decimals: "0"
  },
  data: [
    {
      label: "test1",
      value: "3.5"
    },
    {
      label: "test2",
      value: "-3.5"
    },
    {
      label: "test3",
      value: "-2.5"
    },
    {
      label: "test4",
      value: "+2.4"
    },
    {
      label: "test5",
      value: "-10.5"
    }
  ]
};

I suggest to use this function I delveloped myself that I always use to have good rounding relative numbers (my variables are in french but it works) :

/**
 * Permet d'arrondir un nombre à la décimale souhaitée
 * @param {number} nombre Nombre à arrondir.
 * @param {number} decimales Nombre de décimales à arrondir. (Par défaut 0)
 * @returns {number}
 */
function arrondi(nombre, decimales = 0) {
    if (decimales < -1) throw new Error("Le nombre de décimales ne peut être inférieur à -1.");

    var neg = nombre < 0;
    if (decimales == -1)
        return nombre;
    else {
        var nombre_abs = Math.round(Math.abs(nombre) * Math.pow(10, decimales)) / Math.pow(10, decimales);
        if (neg) return -nombre_abs
        else return nombre_abs;
    }
}

 

 

Share this post


Link to post
Share on other sites

Hope you are keeping well! Thank you for your continued patience.

 

For the issue reported, could you please upgrade your current version to the latest, i.e, FusionCharts Suite XT v3.18.0?

 

To avail of the licensed release, you would need to re-download the entire package from the My Orders section of FusionCharts Product Update Center. PUC URL: https://puc.fusioncharts.com/

 

To download the Evaluation version of FusionCharts Suite XT v3.18.0, please visit the link: https://www.fusioncharts.com/download/fusioncharts-suite

 

Thanks,

Akash.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now