Browse Source

BI-26291 除法丢精度

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

87
dist/fineui.js vendored

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

Loading…
Cancel
Save