zoukankan      html  css  js  c++  java
  • js小数点精度问题

    项目背景是用eharts 渲染数据,其中Y 轴的 刻度尺间隔用 interval,代码中如下:

    yAxis: [
    {
    type : 'value',
    position:'left',
    min:minV,
    max:maxV,
    // splitNumber:5,
    interval:interVal,
    axisLine:{
    lineStyle:{
    color:'#fff'
    }
    },
    axisLabel:{
    show:true,
    textStyle:{
    color:'#6B7D97',
    fontSize:'10'
    },
    formatter:function (value,index) {
    return value.toFixed(4)
    }
    },
    splitLine:{
    show:true,
    lineStyle:{
    color:'#fff',
    1
    }
    },
    splitArea:{
    show:true,
    areaStyle:{
    color:'#F6F8FB'
    }
    }
    },
    {
    type : 'value',
    position:'right',
    min:-raa,
    max:raa,
    yAxisIndex:0,
    splitNumber:8,
    axisLine:{
    lineStyle:{
    color:'#fff'
    }
    },
    axisLabel:{
    show:true,
    textStyle:{
    color:'#6B7D97',
    fontSize:'10'
    },
    formatter:function (value,index) {
    return value.toFixed(2)+'%'
    }
    },
    splitLine:{
    show:true,
    lineStyle:{
    color:'#fff',
    1
    }
    },
    splitArea:{
    show:true,
    areaStyle:{
    color:'#F6F8FB'
    }
    }
    }
    ],

    其中 interval 的小数点在RN项目中的小数点不能超过10位(没有具体测试),总之如果出现0.000346789999999这样的小数点的情况下会导致echarts图无法渲染,尝试用toFixed(6)这样处理的时候,
    间隔的刻度不是我们想要的,因此采用的解决办法是保留小数点后8位,不能四舍五入,因此最终解决办法是:
    0.000346789999999.toString().slice(0,8)用这样的处理方式,保留小数点的位数,同时不用四舍五入,即去尾法。
  • 相关阅读:
    51nod 1416 两点 dfs
    Codeforces Round #424 (Div. 2) A-C
    Codeforces Round #423 (Div. 2) A-C
    Codeforces Round #422 (Div. 2) A-C
    HDU 6077 Time To Get Up 模拟
    51nod 1381 硬币游戏 概率
    51nod 1100 斜率最大 计算几何
    hihocoder 1287 : 数论一·Miller-Rabin质数测试 大质数判定
    字典树
    数论
  • 原文地址:https://www.cnblogs.com/keleyz/p/9981446.html
Copyright © 2011-2022 走看看