Browse Source

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

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

20
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) {
@ -6092,16 +6088,16 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
//如果差值的整数位数大于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) {

20
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) {
@ -6092,16 +6088,16 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
//如果差值的整数位数大于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

20
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) {
@ -432,16 +428,16 @@ BI.IntervalSlider = BI.inherit(BI.Widget, {
//如果差值的整数位数大于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