Browse Source

解决区间滑块数值精度问题

es6
刘荣歆 7 years ago
parent
commit
2ef91f04a0
  1. 70646
      bi/base.js
  2. 24904
      bi/case.js
  3. 22
      bi/widget.js
  4. 70646
      docs/base.js
  5. 24904
      docs/case.js
  6. 17800
      docs/demo.js
  7. 22
      docs/widget.js
  8. 1776
      package-lock.json
  9. 22
      src/widget/intervalslider/intervalslider.js

70646
bi/base.js

File diff suppressed because it is too large Load Diff

24904
bi/case.js

File diff suppressed because it is too large Load Diff

22
bi/widget.js

@ -6040,15 +6040,11 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
var sub = this.calculation.accurateSubtraction(this.max, this.min); var sub = this.calculation.accurateSubtraction(this.max, this.min);
var mul = this.calculation.accurateMultiplication(sub, percent); var mul = this.calculation.accurateMultiplication(sub, percent);
var div = this.calculation.accurateDivisionTenExponent(mul, 2); var div = this.calculation.accurateDivisionTenExponent(mul, 2);
console.log("precision", this.precision);
// console.log(this.calculation.accurateAddition(div, this.min));
if (this.precision >= 0) { if (this.precision >= 0) {
return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision)); return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
} else { } else {
console.log(Math.pow(10, (-1) * this.precision));
return BI.parseFloat(this.calculation.accurateAddition(div, this.min) - this.calculation.accurateAddition(div, this.min) % (Math.pow(10, (-1) * this.precision))); return BI.parseFloat(this.calculation.accurateAddition(div, this.min) - this.calculation.accurateAddition(div, this.min) % (Math.pow(10, (-1) * this.precision)));
} }
//return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
}, },
_getPercentByValue: function (v) { _getPercentByValue: function (v) {
@ -6091,17 +6087,17 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
//计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度) //计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度)
//如果差值的整数位数大于4,toPrecision得到的是科学计数法1234 => 1.2e+3 //如果差值的整数位数大于4,toPrecision得到的是科学计数法1234 => 1.2e+3
var sub = this.calculation.accurateSubtraction(this.max, this.min); var sub = this.calculation.accurateSubtraction(this.max, this.min);
var pre = sub.toPrecision(4); var pre = sub.toPrecision(4);
console.log("pre", pre); if(pre.indexOf("e") > -1 ){
var precisionString = pre.indexOf("e") > -1 ? (BI.parseFloat(sub.toPrecision(4)) + "") : pre;
var arr = precisionString.split(".");
console.log("arr", arr);
if (arr.length > 1) {
this.precision = arr[1].length;
} else {
this.precision = 3 - pre.charAt(pre.length - 1); this.precision = 3 - pre.charAt(pre.length - 1);
}else{
var arr = pre.split(".");
if(arr.length>1){
this.precision = arr[1].length;
}else{
this.precision=0;
}
} }
// this.precision = arr.length > 1 ? arr[1].length : 0;
this._setDraggableEnable(true); this._setDraggableEnable(true);
} }
if (maxNumber === minNumber) { if (maxNumber === minNumber) {

70646
docs/base.js

File diff suppressed because it is too large Load Diff

24904
docs/case.js

File diff suppressed because it is too large Load Diff

17800
docs/demo.js

File diff suppressed because one or more lines are too long

22
docs/widget.js

@ -6040,15 +6040,11 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
var sub = this.calculation.accurateSubtraction(this.max, this.min); var sub = this.calculation.accurateSubtraction(this.max, this.min);
var mul = this.calculation.accurateMultiplication(sub, percent); var mul = this.calculation.accurateMultiplication(sub, percent);
var div = this.calculation.accurateDivisionTenExponent(mul, 2); var div = this.calculation.accurateDivisionTenExponent(mul, 2);
console.log("precision", this.precision);
// console.log(this.calculation.accurateAddition(div, this.min));
if (this.precision >= 0) { if (this.precision >= 0) {
return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision)); return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
} else { } else {
console.log(Math.pow(10, (-1) * this.precision));
return BI.parseFloat(this.calculation.accurateAddition(div, this.min) - this.calculation.accurateAddition(div, this.min) % (Math.pow(10, (-1) * this.precision))); return BI.parseFloat(this.calculation.accurateAddition(div, this.min) - this.calculation.accurateAddition(div, this.min) % (Math.pow(10, (-1) * this.precision)));
} }
//return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
}, },
_getPercentByValue: function (v) { _getPercentByValue: function (v) {
@ -6091,17 +6087,17 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
//计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度) //计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度)
//如果差值的整数位数大于4,toPrecision得到的是科学计数法1234 => 1.2e+3 //如果差值的整数位数大于4,toPrecision得到的是科学计数法1234 => 1.2e+3
var sub = this.calculation.accurateSubtraction(this.max, this.min); var sub = this.calculation.accurateSubtraction(this.max, this.min);
var pre = sub.toPrecision(4); var pre = sub.toPrecision(4);
console.log("pre", pre); if(pre.indexOf("e") > -1 ){
var precisionString = pre.indexOf("e") > -1 ? (BI.parseFloat(sub.toPrecision(4)) + "") : pre;
var arr = precisionString.split(".");
console.log("arr", arr);
if (arr.length > 1) {
this.precision = arr[1].length;
} else {
this.precision = 3 - pre.charAt(pre.length - 1); this.precision = 3 - pre.charAt(pre.length - 1);
}else{
var arr = pre.split(".");
if(arr.length>1){
this.precision = arr[1].length;
}else{
this.precision=0;
}
} }
// this.precision = arr.length > 1 ? arr[1].length : 0;
this._setDraggableEnable(true); this._setDraggableEnable(true);
} }
if (maxNumber === minNumber) { if (maxNumber === minNumber) {

1776
package-lock.json generated

File diff suppressed because it is too large Load Diff

22
src/widget/intervalslider/intervalslider.js

@ -380,15 +380,11 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
var sub = this.calculation.accurateSubtraction(this.max, this.min); var sub = this.calculation.accurateSubtraction(this.max, this.min);
var mul = this.calculation.accurateMultiplication(sub, percent); var mul = this.calculation.accurateMultiplication(sub, percent);
var div = this.calculation.accurateDivisionTenExponent(mul, 2); var div = this.calculation.accurateDivisionTenExponent(mul, 2);
console.log("precision", this.precision);
// console.log(this.calculation.accurateAddition(div, this.min));
if (this.precision >= 0) { if (this.precision >= 0) {
return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision)); return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
} else { } else {
console.log(Math.pow(10, (-1) * this.precision));
return BI.parseFloat(this.calculation.accurateAddition(div, this.min) - this.calculation.accurateAddition(div, this.min) % (Math.pow(10, (-1) * this.precision))); return BI.parseFloat(this.calculation.accurateAddition(div, this.min) - this.calculation.accurateAddition(div, this.min) % (Math.pow(10, (-1) * this.precision)));
} }
//return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
}, },
_getPercentByValue: function (v) { _getPercentByValue: function (v) {
@ -431,17 +427,17 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
//计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度) //计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度)
//如果差值的整数位数大于4,toPrecision得到的是科学计数法1234 => 1.2e+3 //如果差值的整数位数大于4,toPrecision得到的是科学计数法1234 => 1.2e+3
var sub = this.calculation.accurateSubtraction(this.max, this.min); var sub = this.calculation.accurateSubtraction(this.max, this.min);
var pre = sub.toPrecision(4); var pre = sub.toPrecision(4);
console.log("pre", pre); if(pre.indexOf("e") > -1 ){
var precisionString = pre.indexOf("e") > -1 ? (BI.parseFloat(sub.toPrecision(4)) + "") : pre;
var arr = precisionString.split(".");
console.log("arr", arr);
if (arr.length > 1) {
this.precision = arr[1].length;
} else {
this.precision = 3 - pre.charAt(pre.length - 1); this.precision = 3 - pre.charAt(pre.length - 1);
}else{
var arr = pre.split(".");
if(arr.length>1){
this.precision = arr[1].length;
}else{
this.precision=0;
}
} }
// this.precision = arr.length > 1 ? arr[1].length : 0;
this._setDraggableEnable(true); this._setDraggableEnable(true);
} }
if (maxNumber === minNumber) { if (maxNumber === minNumber) {

Loading…
Cancel
Save