Browse Source

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

es6
刘荣歆 7 years ago
parent
commit
2ef91f04a0
  1. 16
      bi/widget.js
  2. 16
      docs/widget.js
  3. 1776
      package-lock.json
  4. 16
      src/widget/intervalslider/intervalslider.js

16
bi/widget.js

@ -6040,15 +6040,11 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
var sub = this.calculation.accurateSubtraction(this.max, this.min);
var mul = this.calculation.accurateMultiplication(sub, percent);
var div = this.calculation.accurateDivisionTenExponent(mul, 2);
console.log("precision", this.precision);
// console.log(this.calculation.accurateAddition(div, this.min));
if (this.precision >= 0) {
return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
} 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).toFixed(this.precision));
},
_getPercentByValue: function (v) {
@ -6092,16 +6088,16 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
//如果差值的整数位数大于4,toPrecision得到的是科学计数法1234 => 1.2e+3
var sub = this.calculation.accurateSubtraction(this.max, this.min);
var pre = sub.toPrecision(4);
console.log("pre", pre);
var precisionString = pre.indexOf("e") > -1 ? (BI.parseFloat(sub.toPrecision(4)) + "") : pre;
var arr = precisionString.split(".");
console.log("arr", arr);
if(pre.indexOf("e") > -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 = 3 - pre.charAt(pre.length - 1);
this.precision=0;
}
}
// this.precision = arr.length > 1 ? arr[1].length : 0;
this._setDraggableEnable(true);
}
if (maxNumber === minNumber) {

16
docs/widget.js

@ -6040,15 +6040,11 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
var sub = this.calculation.accurateSubtraction(this.max, this.min);
var mul = this.calculation.accurateMultiplication(sub, percent);
var div = this.calculation.accurateDivisionTenExponent(mul, 2);
console.log("precision", this.precision);
// console.log(this.calculation.accurateAddition(div, this.min));
if (this.precision >= 0) {
return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
} 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).toFixed(this.precision));
},
_getPercentByValue: function (v) {
@ -6092,16 +6088,16 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
//如果差值的整数位数大于4,toPrecision得到的是科学计数法1234 => 1.2e+3
var sub = this.calculation.accurateSubtraction(this.max, this.min);
var pre = sub.toPrecision(4);
console.log("pre", pre);
var precisionString = pre.indexOf("e") > -1 ? (BI.parseFloat(sub.toPrecision(4)) + "") : pre;
var arr = precisionString.split(".");
console.log("arr", arr);
if(pre.indexOf("e") > -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 = 3 - pre.charAt(pre.length - 1);
this.precision=0;
}
}
// this.precision = arr.length > 1 ? arr[1].length : 0;
this._setDraggableEnable(true);
}
if (maxNumber === minNumber) {

1776
package-lock.json generated

File diff suppressed because it is too large Load Diff

16
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 mul = this.calculation.accurateMultiplication(sub, percent);
var div = this.calculation.accurateDivisionTenExponent(mul, 2);
console.log("precision", this.precision);
// console.log(this.calculation.accurateAddition(div, this.min));
if (this.precision >= 0) {
return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision));
} 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).toFixed(this.precision));
},
_getPercentByValue: function (v) {
@ -432,16 +428,16 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
//如果差值的整数位数大于4,toPrecision得到的是科学计数法1234 => 1.2e+3
var sub = this.calculation.accurateSubtraction(this.max, this.min);
var pre = sub.toPrecision(4);
console.log("pre", pre);
var precisionString = pre.indexOf("e") > -1 ? (BI.parseFloat(sub.toPrecision(4)) + "") : pre;
var arr = precisionString.split(".");
console.log("arr", arr);
if(pre.indexOf("e") > -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 = 3 - pre.charAt(pre.length - 1);
this.precision=0;
}
}
// this.precision = arr.length > 1 ? arr[1].length : 0;
this._setDraggableEnable(true);
}
if (maxNumber === minNumber) {

Loading…
Cancel
Save