Browse Source

BI-26291 除法丢精度

es6
Young 6 years ago
parent
commit
9b23bee3da
  1. 87
      dist/bundle.js
  2. 17
      dist/case.js
  3. 70
      dist/core.js
  4. 87
      dist/fineui.js
  5. 70
      src/core/proto/number.js
  6. 70
      utils/utils.js

87
dist/bundle.js vendored

@ -29973,32 +29973,66 @@ function accMul (arg1, arg2) {
Number.prototype.mul = function (arg) {
return accMul(arg, this);
};
/**
** 除法函数用来得到精确的除法结果
** 说明javascript的除法结果会有误差在两个浮点数相除的时候会比较明显这个函数返回较为精确的除法结果
** 调用accDiv(arg1,arg2)
** 返回值arg1除以arg2的精确结果
**/
function accDiv (arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try {
t1 = arg1.toString().split(".")[1].length;
} catch (e) {
* Return digits length of a number
* @param {*number} num Input number
*/
function digitLength (num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0));
return len > 0 ? len : 0;
}
/**
* 把小数转成整数支持科学计数法如果是小数则放大成整数
* @param {*number} num 输入数
*/
function float2Fixed (num) {
if (num.toString().indexOf("e") === -1) {
return Number(num.toString().replace(".", ""));
}
try {
t2 = arg2.toString().split(".")[1].length;
} catch (e) {
var dLen = digitLength(num);
return dLen > 0 ? num * Math.pow(10, dLen) : num;
}
/**
* 精确乘法
*/
function times (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
if (others.length > 0) {
return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
return leftValue / Math.pow(10, baseNum);
}
/**
* 精确除法
*/
function accDivide (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
with (Math) {
r1 = Number(arg1.toString().replace(".", ""));
r2 = Number(arg2.toString().replace(".", ""));
return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2);
if (others.length > 0) {
return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1)));
}
// 给Number类型增加一个div方法,调用起来更加方便。
Number.prototype.div = function (arg) {
return accDiv(this, arg);
return accDivide(this, arg);
};/**
* 对字符串对象的扩展
* @class String
@ -83174,11 +83208,6 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, {
editor: o.editor
});
}));
this.element.mousedown(function (e) {
BI.each(buttons, function (i, btn) {
btn.hideIf(e);
});
});
BI.createWidget({
type: "bi.left",
element: this,
@ -83300,6 +83329,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/**
return this.instance.getContent();
},
getContentHeight: function () {
return this.instance.getContentHeight();
},
getInstance: function () {
return this.instance;
},
@ -83509,6 +83542,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/**
return this.content;
},
getContentHeight: function () {
return this.elm.element.height();
},
setContent: function (e) {
this.content = e;
this.ne.fireEvent("set");
@ -84274,6 +84311,10 @@ BI.RichEditor = BI.inherit(BI.Widget, {
getValue: function () {
return this.editor.getValue();
},
getContentHeight: function () {
return this.editor.getContentHeight();
}
});
BI.RichEditor.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";

17
dist/case.js vendored

@ -10673,11 +10673,6 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, {
editor: o.editor
});
}));
this.element.mousedown(function (e) {
BI.each(buttons, function (i, btn) {
btn.hideIf(e);
});
});
BI.createWidget({
type: "bi.left",
element: this,
@ -10799,6 +10794,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/**
return this.instance.getContent();
},
getContentHeight: function () {
return this.instance.getContentHeight();
},
getInstance: function () {
return this.instance;
},
@ -11008,6 +11007,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/**
return this.content;
},
getContentHeight: function () {
return this.elm.element.height();
},
setContent: function (e) {
this.content = e;
this.ne.fireEvent("set");
@ -11773,6 +11776,10 @@ BI.RichEditor = BI.inherit(BI.Widget, {
getValue: function () {
return this.editor.getValue();
},
getContentHeight: function () {
return this.editor.getContentHeight();
}
});
BI.RichEditor.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";

70
dist/core.js vendored

@ -29973,32 +29973,66 @@ function accMul (arg1, arg2) {
Number.prototype.mul = function (arg) {
return accMul(arg, this);
};
/**
** 除法函数用来得到精确的除法结果
** 说明javascript的除法结果会有误差在两个浮点数相除的时候会比较明显这个函数返回较为精确的除法结果
** 调用accDiv(arg1,arg2)
** 返回值arg1除以arg2的精确结果
**/
function accDiv (arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try {
t1 = arg1.toString().split(".")[1].length;
} catch (e) {
* Return digits length of a number
* @param {*number} num Input number
*/
function digitLength (num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0));
return len > 0 ? len : 0;
}
/**
* 把小数转成整数支持科学计数法如果是小数则放大成整数
* @param {*number} num 输入数
*/
function float2Fixed (num) {
if (num.toString().indexOf("e") === -1) {
return Number(num.toString().replace(".", ""));
}
try {
t2 = arg2.toString().split(".")[1].length;
} catch (e) {
var dLen = digitLength(num);
return dLen > 0 ? num * Math.pow(10, dLen) : num;
}
/**
* 精确乘法
*/
function times (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
if (others.length > 0) {
return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
return leftValue / Math.pow(10, baseNum);
}
/**
* 精确除法
*/
function accDivide (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
with (Math) {
r1 = Number(arg1.toString().replace(".", ""));
r2 = Number(arg2.toString().replace(".", ""));
return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2);
if (others.length > 0) {
return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1)));
}
// 给Number类型增加一个div方法,调用起来更加方便。
Number.prototype.div = function (arg) {
return accDiv(this, arg);
return accDivide(this, arg);
};/**
* 对字符串对象的扩展
* @class String

87
dist/fineui.js vendored

@ -30222,32 +30222,66 @@ function accMul (arg1, arg2) {
Number.prototype.mul = function (arg) {
return accMul(arg, this);
};
/**
** 除法函数用来得到精确的除法结果
** 说明javascript的除法结果会有误差在两个浮点数相除的时候会比较明显这个函数返回较为精确的除法结果
** 调用accDiv(arg1,arg2)
** 返回值arg1除以arg2的精确结果
**/
function accDiv (arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try {
t1 = arg1.toString().split(".")[1].length;
} catch (e) {
* Return digits length of a number
* @param {*number} num Input number
*/
function digitLength (num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0));
return len > 0 ? len : 0;
}
/**
* 把小数转成整数支持科学计数法如果是小数则放大成整数
* @param {*number} num 输入数
*/
function float2Fixed (num) {
if (num.toString().indexOf("e") === -1) {
return Number(num.toString().replace(".", ""));
}
try {
t2 = arg2.toString().split(".")[1].length;
} catch (e) {
var dLen = digitLength(num);
return dLen > 0 ? num * Math.pow(10, dLen) : num;
}
/**
* 精确乘法
*/
function times (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
if (others.length > 0) {
return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
return leftValue / Math.pow(10, baseNum);
}
/**
* 精确除法
*/
function accDivide (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
with (Math) {
r1 = Number(arg1.toString().replace(".", ""));
r2 = Number(arg2.toString().replace(".", ""));
return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2);
if (others.length > 0) {
return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1)));
}
// 给Number类型增加一个div方法,调用起来更加方便。
Number.prototype.div = function (arg) {
return accDiv(this, arg);
return accDivide(this, arg);
};/**
* 对字符串对象的扩展
* @class String
@ -83423,11 +83457,6 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, {
editor: o.editor
});
}));
this.element.mousedown(function (e) {
BI.each(buttons, function (i, btn) {
btn.hideIf(e);
});
});
BI.createWidget({
type: "bi.left",
element: this,
@ -83549,6 +83578,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/**
return this.instance.getContent();
},
getContentHeight: function () {
return this.instance.getContentHeight();
},
getInstance: function () {
return this.instance;
},
@ -83758,6 +83791,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/**
return this.content;
},
getContentHeight: function () {
return this.elm.element.height();
},
setContent: function (e) {
this.content = e;
this.ne.fireEvent("set");
@ -84523,6 +84560,10 @@ BI.RichEditor = BI.inherit(BI.Widget, {
getValue: function () {
return this.editor.getValue();
},
getContentHeight: function () {
return this.editor.getContentHeight();
}
});
BI.RichEditor.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";

70
src/core/proto/number.js

@ -232,30 +232,64 @@ function accMul (arg1, arg2) {
Number.prototype.mul = function (arg) {
return accMul(arg, this);
};
/**
** 除法函数用来得到精确的除法结果
** 说明javascript的除法结果会有误差在两个浮点数相除的时候会比较明显这个函数返回较为精确的除法结果
** 调用accDiv(arg1,arg2)
** 返回值arg1除以arg2的精确结果
**/
function accDiv (arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try {
t1 = arg1.toString().split(".")[1].length;
} catch (e) {
* Return digits length of a number
* @param {*number} num Input number
*/
function digitLength (num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0));
return len > 0 ? len : 0;
}
/**
* 把小数转成整数支持科学计数法如果是小数则放大成整数
* @param {*number} num 输入数
*/
function float2Fixed (num) {
if (num.toString().indexOf("e") === -1) {
return Number(num.toString().replace(".", ""));
}
try {
t2 = arg2.toString().split(".")[1].length;
} catch (e) {
var dLen = digitLength(num);
return dLen > 0 ? num * Math.pow(10, dLen) : num;
}
/**
* 精确乘法
*/
function times (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
if (others.length > 0) {
return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
return leftValue / Math.pow(10, baseNum);
}
/**
* 精确除法
*/
function accDivide (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
with (Math) {
r1 = Number(arg1.toString().replace(".", ""));
r2 = Number(arg2.toString().replace(".", ""));
return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2);
if (others.length > 0) {
return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1)));
}
// 给Number类型增加一个div方法,调用起来更加方便。
Number.prototype.div = function (arg) {
return accDiv(this, arg);
return accDivide(this, arg);
};

70
utils/utils.js

@ -10416,32 +10416,66 @@ function accMul (arg1, arg2) {
Number.prototype.mul = function (arg) {
return accMul(arg, this);
};
/**
** 除法函数用来得到精确的除法结果
** 说明javascript的除法结果会有误差在两个浮点数相除的时候会比较明显这个函数返回较为精确的除法结果
** 调用accDiv(arg1,arg2)
** 返回值arg1除以arg2的精确结果
**/
function accDiv (arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try {
t1 = arg1.toString().split(".")[1].length;
} catch (e) {
* Return digits length of a number
* @param {*number} num Input number
*/
function digitLength (num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0));
return len > 0 ? len : 0;
}
/**
* 把小数转成整数支持科学计数法如果是小数则放大成整数
* @param {*number} num 输入数
*/
function float2Fixed (num) {
if (num.toString().indexOf("e") === -1) {
return Number(num.toString().replace(".", ""));
}
try {
t2 = arg2.toString().split(".")[1].length;
} catch (e) {
var dLen = digitLength(num);
return dLen > 0 ? num * Math.pow(10, dLen) : num;
}
/**
* 精确乘法
*/
function times (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
if (others.length > 0) {
return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
return leftValue / Math.pow(10, baseNum);
}
/**
* 精确除法
*/
function accDivide (num1, num2) {
var others = [];
for (var _i = 2; _i < arguments.length; _i++) {
others[_i - 2] = arguments[_i];
}
with (Math) {
r1 = Number(arg1.toString().replace(".", ""));
r2 = Number(arg2.toString().replace(".", ""));
return (t2 > t1) ? (r1 / r2) * pow(10, t2 - t1) : (r1 / r2) / pow(10, t1 - t2);
if (others.length > 0) {
return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1)));
}
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1)));
}
// 给Number类型增加一个div方法,调用起来更加方便。
Number.prototype.div = function (arg) {
return accDiv(this, arg);
return accDivide(this, arg);
};/**
* 对字符串对象的扩展
* @class String

Loading…
Cancel
Save