You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HENGCHENG/DSWeb/js/DoPayApplicationSettlement2.js

720 lines
29 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

var mygrid_recv_2;
var page_count = 5;
var column_count;
var jsonWmsZXInfoObj;
var changeCount = 0;
//两端去空格函数
String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }
function $(id) {
return document.getElementById(id);
}
function initWinScreen2() {
var winScreenHeight = 0;
var winScreenWidth = 0;
if (window.screen.height) {
winScreenHeight = window.screen.height;
}
if (window.screen.width) {
winScreenWidth = window.screen.width;
}
if (winScreenWidth >= 1440 && winScreenWidth >= 900) {
document.getElementById("mygrid_recv_2").style.height = "580px";
}
else if (winScreenWidth >= 1366 && winScreenWidth >= 768) {
document.getElementById("mygrid_recv_2").style.height = "340px";
}
else if (winScreenWidth >= 1024 && winScreenWidth >= 768) {
document.getElementById("mygrid_recv_2").style.height = "300px";
}
}
function initGrid2(handle,settlementid,billno) {
mygrid_recv_2 = new dhtmlXGridObject('mygrid_recv_2');
mygrid_recv_2.setImagePath("../images/");
mygrid_recv_2.setSkin("xp");
// 0 1 2 3 4 5 6 7 8 9 10 11 12
//mygrid_recv_2.setHeader("<input type=\"checkbox\" id=\"ck_all\" onclick=\"checkall2()\" />,计费等级,费用类别,计费区间,单位,单价,增值价,封顶价,结束计费日期,备注,创建人,创建时间,委托单号");
// 0 1 2 3 4 5 6 7 8
mygrid_recv_2.setHeader("选择,客户名称,单号,实录时间,币别,汇率,实录金额,未核销金额,本次核销"); //<input type=\"checkbox\" id=\"ck_all\" onclick=\"checkall2()\" />
mygrid_recv_2.setInitWidths("30,120,100,120,50,50,80,80,80");
mygrid_recv_2.setColAlign("center,center,center,center,center,center,center,center,center");
mygrid_recv_2.setColSorting("na,str,str,str,str,str,str,str,str");
mygrid_recv_2.setColTypes("ch,ro,ro,ro,ro,ro,ro,ro,ed");
var urlVal = "../Settlements/DoPayApplicationSettlementGridSource.aspx?read=exist&customername=" + escape($("txt_customerName").value) + "&handle=" + handle + "&settlementid=" + settlementid + "&billno=" + billno + "&feetype=" + $("h_feetype").value + "&val=" + newGuid();
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
loader = null;
if (parseInt(loadVal) == 1) {
mygrid_recv_2.loadXML("../Settlements/DoPayApplicationSettlementGridSource.aspx?read=init&customername=" + escape($("txt_customerName").value) + "&handle=" + handle + "&settlementid=" + settlementid + "&billno=" + billno + "&feetype=" + $("h_feetype").value + "&val=" + newGuid());
setTimeout(function() {
}, 200);
}
mygrid_recv_2.init();
mygrid_recv_2.enableEditEvents(true, false, true);
mygrid_recv_2.enableMultiselect(true);
mygrid_recv_2.enableKeyboardSupport(true);
var pushVal = "";
var pressRecord = "";
var pressRowIndex = -1;
var pressCellIndex = -1;
var pressCount = 0;
var isExchange = false;
var shiftCount = 0;
var isDelete = 0;
var flagFilter = 0;
var flagTab = 0;
var flagEnter = 0;
var flagDelete = 0;
//手动编写Grid控件编辑事件,由于免费控件没有提供完整的编辑判断功能,现特此做更改
mygrid_recv_2.attachEvent("onEditCell", function (stage, rId, cInd, nValue, oValue) {
var newCheckValue = false;
//初始化状态
if (stage == 0) {
var selectedId = mygrid_recv_2.getSelectedRowId();
var rowIndex = mygrid_recv_2.getRowIndex(selectedId);
var oldVal = mygrid_recv_2.cellByIndex(rowIndex, 0).getValue().trim();
if (cInd == 0) {
return false;
}
return true;
}
if (stage == 1) {
var rowIndex = mygrid_recv_2.getRowIndex(rId);
var txtEdit;
for (i = 0; i < document.all.length; i++) {
if (document.all(i).tagName == "TEXTAREA") {
txtEdit = document.all(i);
txtEdit.focus();
txtEdit.select();
break;
}
}
}
//如果编辑结束
if (stage == 2) {
//获取当前RowIndex
var rowIndex = mygrid_recv_2.getRowIndex(rId);
if (cInd == 8) {
var wj = parseFloat(mygrid_recv_2.cellByIndex(rowIndex, 7).getValue().trim());
if (nValue.trim() != "") {
var isint = IsNum(nValue);
if (!isint) {
mygrid_recv_2.cellByIndex(rowIndex, cInd).setLabel("0.00");
return true;
}
//
if (parseFloat(nValue.trim()) > wj) {
alert("本次核销金额不能大于未核销金额!");
mygrid_recv_2.cellByIndex(rowIndex, cInd).setLabel("0.00");
return true;
}
//取数(包含负数)
mygrid_recv_2.cellByIndex(rowIndex, 0).setValue(1);
var bb = mygrid_recv_2.cellByIndex(rowIndex, 4).getValue().trim();
var hl = mygrid_recv_2.cellByIndex(rowIndex, 5).getValue().trim();
//
var je1 = parseFloat($("txt_je1").value.trim());
var je2 = parseFloat($("txt_je2").value.trim());
var je3 = parseFloat($("txt_je3").value.trim());
var je4 = parseFloat($("txt_je4").value.trim());
var je5 = parseFloat($("txt_je5").value.trim());
var hl1 = parseFloat($("txt_hl1").value.trim());
var hl2 = parseFloat($("txt_hl2").value.trim());
var hl3 = parseFloat($("txt_hl3").value.trim());
var hl4 = parseFloat($("txt_hl4").value.trim());
var hl5 = parseFloat($("txt_hl5").value.trim());
var bb3 = $("ddl_bb3").value.trim();
if (oValue.trim() == "") {
oValue = 0;
}
var hx = parseFloat(nValue) - parseFloat(oValue);
$("txt_je5").value = Add(je5 * hl5, hx * hl, 2);
if (bb == "USD") {
$("txt_je5").value = Div((je5 * hl5 + hx * hl), hl, 2);
}
$("h_je5").value = $("txt_je5").value;
var je32 = Cut((je1 * hl1 + je2 * hl2), ((je5 * hl5 + hx * hl) + je4 * hl4), 2);
if (je32 < 0) {
$("txt_je3").value = 0;
var je42 = Add(je4, je32, 2);
$("txt_je4").value = je42; //财务费用为RMB
}
else {
$("txt_je3").value = je32;
if (bb3 == "USD") {
$("txt_je3").value = Div(je32, hl3, 2);
}
$("txt_je4").value = round2(((je1 * hl1 + je2 * hl2) - (je5 * hl5 + hx * hl) - je32), 2);
}
//
$("ddl_bb5").value = bb;
$("h_bb5").value = bb;
$("txt_hl5").value = hl;
//$("txt_je5").value = round2(nValue, 2);
//#region 分开取大于0的数并把小于等于0的设为0
// if (parseFloat(nValue.trim()) > 0) {
// mygrid_recv_2.cellByIndex(rowIndex, 0).setValue(1);
// var bb = mygrid_recv_2.cellByIndex(rowIndex, 4).getValue().trim();
// var hl = mygrid_recv_2.cellByIndex(rowIndex, 5).getValue().trim();
// $("ddl_bb5").value = bb;
// $("h_bb5").value = bb;
// $("txt_hl5").value = hl;
// $("txt_je5").value = round2(nValue, 2);
// //
// var je1 = parseFloat($("txt_je1").value.trim());
// var je2 = parseFloat($("txt_je2").value.trim());
// var je3 = parseFloat($("txt_je3").value.trim());
// var je4 = parseFloat($("txt_je4").value.trim());
// var je5 = parseFloat($("txt_je5").value.trim());
// var hx = parseFloat(nValue) - parseFloat(oValue);
// $("txt_je5").value = round2((je5 + (hx)),2);
// var je32 = round2(((je1 + je2) - ((je5 + (hx)) + je4)),2);
// if (je32 < 0) {
// $("txt_je3").value = 0;
// var je42 = round2((je4 + (je32)),2);
// $("txt_je4").value = je42;
// }
// else {
// $("txt_je3").value = je32;
// $("txt_je4").value = round2(((je1 + je2) - (je5 + (hx)) - je32),2);
// }
// }
// else {
// mygrid_recv_2.cellByIndex(rowIndex, 0).setValue(0);
// mygrid_recv_2.cellByIndex(rowIndex, cInd).setLabel("0.00");
// var bb = mygrid_recv_2.cellByIndex(rowIndex, 4).getValue().trim();
// var hl = mygrid_recv_2.cellByIndex(rowIndex, 5).getValue().trim();
// $("ddl_bb5").value = "RMB";
// $("h_bb5").value = "RMB";
// $("txt_hl5").value = "1";
// $("txt_je5").value = "0";
// //
// var je1 = parseFloat($("txt_je1").value.trim());
// var je2 = parseFloat($("txt_je2").value.trim());
// var je3 = parseFloat($("txt_je3").value.trim());
// var je4 = parseFloat($("txt_je4").value.trim());
// var je5 = parseFloat($("txt_je5").value.trim());
// var hx = parseFloat(oValue);
// $("txt_je5").value = round2((je5 - hx),2);
// var je32 = round2(((je1 + je2) - (je5 - hx) - je4),2);
// if (je32 < 0) {
// $("txt_je3").value = 0;
// var je42 = round2((je4 + (je32)),2);
// $("txt_je4").value = je42;
// }
// else {
// $("txt_je3").value = je32;
// $("txt_je4").value = round2(((je1 + je2) - (je5 - hx) - je32),2);
// }
// }
//#endregion
}
return true;
}
else {
return true;
}
}
});
//键盘操作事件
mygrid_recv_2.attachEvent("onKeyPress", function (code, cFlag, sFlag) {
//onKeyPress begin
//获取当前RowID
var selectedId = mygrid_recv_2.getSelectedRowId();
//获取当前RowIndex
var rowIndex = mygrid_recv_2.getRowIndex(selectedId);
//获取当前CellIndex(ind)
var ind = mygrid_recv_2.getSelectedCellIndex();
//触发操作事件前获取单元值
var oldVal = mygrid_recv_2.cellByIndex(rowIndex, ind).getValue();
//获取编辑单元
var txtEdit;
for (i = 0; i < document.all.length; i++) {
if (document.all(i).tagName == "TEXTAREA") {
txtEdit = document.all(i);
break;
}
}
if (code >= 65 && code <= 90) {//如果是输入英文字符
return false;
}
else {
return true;
}
});
setTimeout(function() {
markStatusColor2(mygrid_recv_2);
}, 400);
}
function saveRecvChange2() {
mygrid_recv_2.editStop();
var jsonRateObj = null;
for (var i = 0; i < mygrid_recv_2.getRowsNum(); i++) {
var rowId = mygrid_recv_2.getRowId(i);
var isbool = mygrid_recv_2.cellByIndex(i, 0).getValue();
if (isbool == "1") {
// 1 2 3 4 5 6 7
//客户名称,单号,实录时间,币别,实录金额,未核销金额,本次核销");
var CUSTOMERNAME = mygrid_recv_2.cellByIndex(i, 1).getValue(); //客户名称
var BILLNO = mygrid_recv_2.cellByIndex(i, 2).getValue(); //单号
var CREATETIME = mygrid_recv_2.cellByIndex(i, 3).getValue(); //实录时间
var CURRENCY = mygrid_recv_2.cellByIndex(i, 4).getValue(); //币别
var EXCHANGERATE = mygrid_recv_2.cellByIndex(i, 5).getValue(); //汇率
var AMOUNT = mygrid_recv_2.cellByIndex(i, 6).getValue(); //实录金额
var DOAMOUNT2 = mygrid_recv_2.cellByIndex(i, 7).getValue(); //未核销金额
var DOAMOUNT = mygrid_recv_2.cellByIndex(i, 8).getValue(); //本次核销
var ISFINISH = 0; //是否全部完成核销
if (i != 0 && parseFloat(DOAMOUNT) == 0) {
$("recvContainer_2").value = "";
alert("“本次核销”不能为零");
return -1;
}
if (DOAMOUNT == DOAMOUNT2) {
ISFINISH = 1;
}
//
if (jsonRateObj == null) {
var cacheBuffer = "";
cacheBuffer += "{";
cacheBuffer += "\"GID\":\"" + rowId + "\",";
cacheBuffer += "\"CUSTOMERNAME\":\"" + CUSTOMERNAME + "\",";
cacheBuffer += "\"BILLNO\":\"" + BILLNO + "\",";
cacheBuffer += "\"CREATETIME\":\"" + CREATETIME + "\",";
cacheBuffer += "\"CURRENCY\":\"" + CURRENCY + "\",";
cacheBuffer += "\"AMOUNT\":\"" + AMOUNT + "\",";
cacheBuffer += "\"DOAMOUNT2\":\"" + DOAMOUNT2 + "\",";
cacheBuffer += "\"DOAMOUNT\":\"" + DOAMOUNT + "\",";
cacheBuffer += "\"ISFINISH\":\"" + ISFINISH + "\"";
cacheBuffer += "}";
var result = "";
result += "{\"rates\":[";
result += cacheBuffer;
result += "]}";
jsonRateObj = eval('(' + result + ')');
} else {
var newRateRow = jsonRateObj.rates;
newRateRow = { GID: rowId, CUSTOMERNAME: CUSTOMERNAME, BILLNO: BILLNO, CREATETIME: CREATETIME, CURRENCY: CURRENCY, AMOUNT: AMOUNT, DOAMOUNT2: DOAMOUNT2, DOAMOUNT: DOAMOUNT, ISFINISH: ISFINISH };
jsonRateObj.rates.push(newRateRow);
}
}
}
if (jsonRateObj != null) {
$("recvContainer_2").value = JSON.stringify(jsonRateObj);
}
return 1;
}
//post数据
function postEnter() {
var myForm = document.getElementById("form1");
myForm.submit();
}
function markStatusColor2(gridObj) {
var count = gridObj.getRowsNum();
for (var i = 0; i < count; i++) {
var status = gridObj.cellByIndex(i, 0).getValue();
var rowId = gridObj.getRowId(i);
}
}
//全选框
function checkall2() {
var checkStatus = $("ck_all").checked;
if (checkStatus == 1) {
var iCount = mygrid_recv_2.getRowsNum();
for (var i = 0; i < iCount; i++) {
mygrid_recv_2.cellByIndex(i, 0).setValue(1);
}
}
else {
var iCount = mygrid_recv_2.getRowsNum();
for (var i = 0; i < iCount; i++) {
mygrid_recv_2.cellByIndex(i, 0).setValue(0);
}
}
}
//获取GUID
function newGuid() {
var guid = "";
for (var i = 1; i <= 32; i++) {
var n = Math.floor(Math.random() * 16.0).toString(16);
guid += n;
if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
guid += "-";
}
return guid.toUpperCase();
}
//------------------------------------------------------------------------------------------------------------------------
function clearNoNum2(valObj) {
//先把非数字的都替换掉,除了数字和.
valObj = valObj.replace(/[^\d.]/g, "");
//必须保证第一个为数字而不是.
valObj = valObj.replace(/^\./g, "");
//保证只有出现一个.而没有多个.
valObj = valObj.replace(/\.{2,}/g, ".");
//保证.只出现一次,而不能出现两次以上
valObj = valObj.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
return valObj;
}
//是否为数字
function IsNum(val) {
var re = /^[-\+]?\d+(\.\d+)?$/;
if (!re.test(val)) {
return false;
} else {
return true;
}
}
//是否为数字,且数值格式是否正确
function IsNumFormat(val) {
var re = /^[-\+]?\d+(\.\d+)?$/;
if (!re.test(val)) {
return false;
}
else {
if (val.toString().indexOf(".") > 0) {
val.toString().replace("-", "");
val.toString().replace("+", "");
if (val.toString().substr(0, 1) == "0" && val.toString().substr(0, 2) != "0.") {
return false;
}
}
else {
var re1 = /^[-\+]+[1-9]+[0-9]*]*$/;
if (!re1.test(val)) {
re1 = /^[1-9]+[0-9]*]*$/;
if (!re1.test(val)) {
return false;
}
}
}
return true;
}
}
//是否为整数
function IsIntFormat(val) {
re1 = /^[1-9]+[0-9]*]*$/;
if (!re1.test(val)) {
return false;
}
return true;
}
//
function getIsNum(x) {
var str = x.value.trim();
if (str == "0") {
return;
}
else if (str == "") {
str = 0;
x.value = 0;
}
else {
var bl = IsNumFormat(str);
if (!bl) {
alert("数值格式错误!");
x.focus();
x.select();
}
}
}
//-------------------------------------------------------------------------------------------------------
function txt_disabled() {
document.getElementById('ddl_bb1').disabled = true;
document.getElementById('ddl_bb2').disabled = false; // true;
document.getElementById('ddl_bb3').disabled = false;
document.getElementById('ddl_bb4').disabled = false;
document.getElementById('ddl_bb5').disabled = true;
document.getElementById('txt_hl1').readOnly = true;
document.getElementById('txt_hl2').readOnly = false; // true
document.getElementById('txt_hl3').readOnly = false;
document.getElementById('txt_hl4').readOnly = false;
document.getElementById('txt_hl5').readOnly = true
document.getElementById('txt_je1').readOnly = false;
document.getElementById('txt_je2').readOnly = false; // true
document.getElementById('txt_je3').readOnly = false;
document.getElementById('txt_je4').readOnly = false;
document.getElementById('txt_je5').readOnly = true
document.getElementById('txt_hl1').style.color = "#808080";
document.getElementById('txt_hl2').style.color = "#000000"; // "#808080";
document.getElementById('txt_hl3').style.color = "#000000";
document.getElementById('txt_hl4').style.color = "#000000";
document.getElementById('txt_hl5').style.color = "#808080";
document.getElementById('txt_je1').style.color = "#000000";
document.getElementById('txt_je2').style.color = "#000000"; // "#808080";
document.getElementById('txt_je3').style.color = "#000000";
document.getElementById('txt_je4').style.color = "#000000";
document.getElementById('txt_je5').style.color = "#808080";
}
function txt_je1_onblur() {
if ($("txt_je1").value.trim() != "") {
var oje1 = parseFloat($("h_je1").value.trim());
var je1 = parseFloat($("txt_je1").value.trim());
var je4 = parseFloat($("txt_je4").value.trim());
var je5 = parseFloat($("txt_je5").value.trim());
var hl1 = parseFloat($("txt_hl1").value.trim());
var hl3 = parseFloat($("txt_hl3").value.trim());
var hl4 = parseFloat($("txt_hl4").value.trim());
var hl5 = parseFloat($("txt_hl5").value.trim());
var bb3 = $("ddl_bb3").value.trim();
$("txt_je2").value = round2((je1 - oje1),2);
$("txt_je3").value = round2((je1 * hl1 - je4 * hl4 - je5 * hl5), 2);
if (bb3 == "USD") {
$("txt_je3").value = Div((je1 * hl1 - je4 * hl4 - je5 * hl5), hl3, 2);
}
$("txt_je1").value = oje1;
//#region 分开取大于0的数并把小于等于0的设为0
// if (je1 > oje1) {
// $("txt_je2").value = round2((je1 - oje1),2);
// $("txt_je3").value = round2((je1 * hl1 - je4 * hl4 - je5 * hl5), 2);
// if (bb3 == "USD") {
// $("txt_je3").value = Div((je1 * hl1 - je4 * hl4 - je5 * hl5), hl3, 2);
// }
// }
// else {
// $("txt_je2").value = "0.00";
// }
// $("txt_je1").value = oje1;
//#endregion
}
}
function txt_je3_onblur() {
if ($("txt_je3").value.trim() != "") {
var je1 = parseFloat($("txt_je1").value.trim());
var je2 = parseFloat($("txt_je2").value.trim());
var je3 = parseFloat($("txt_je3").value.trim());
var je5 = parseFloat($("txt_je5").value.trim());
var hl1 = parseFloat($("txt_hl1").value.trim());
var hl2 = parseFloat($("txt_hl2").value.trim());
var hl3 = parseFloat($("txt_hl3").value.trim());
var hl5 = parseFloat($("txt_hl5").value.trim());
$("txt_je4").value = round2((je1 * hl1 + je2 * hl2 - je3 * hl3 - je5 * hl5), 2);
}
}
function txt_je4_onblur() {
if ($("txt_je4").value.trim() != "") {
var je1 = parseFloat($("txt_je1").value.trim());
var je2 = parseFloat($("txt_je2").value.trim());
var je4 = parseFloat($("txt_je4").value.trim());
var je5 = parseFloat($("txt_je5").value.trim());
var hl1 = parseFloat($("txt_hl1").value.trim());
var hl2 = parseFloat($("txt_hl2").value.trim());
var hl3 = parseFloat($("txt_hl3").value.trim());
var hl4 = parseFloat($("txt_hl4").value.trim());
var hl5 = parseFloat($("txt_hl5").value.trim());
var bb3 = $("ddl_bb3").value.trim();
$("txt_je3").value = round2((je1 * hl1 + je2 * hl2 - je4 * hl4 - je5 * hl5), 2);
if (bb3 == "USD") {
$("txt_je3").value = Div((je1 * hl1 + je2 * hl2 - je4 * hl4 - je5 * hl5), hl3, 2);
}
}
}
function setAccess(handle) {
if ($("h_isAccess").value.trim() == "0") {
$("h_isAccess").value = "1";
document.getElementById('mygrid_recv_2').style.display = "";
if (handle.toString().trim() == "add") {
initGrid2("add", "", "");
}
else {
initGrid2("edit", $("h_settlementid").value.trim(), $("h_billno").value.trim());
}
}
else if ($("h_isAccess").value.trim() == "1") {
$("h_isAccess").value = "0";
document.getElementById('mygrid_recv_2').style.display = "none";
//
var hl1 = parseFloat($("txt_hl1").value.trim());
var je1 = parseFloat($("txt_je1").value.trim());
var je2 = parseFloat($("txt_je2").value.trim());
var je3 = parseFloat($("txt_je3").value.trim());
var je4 = parseFloat($("txt_je4").value.trim());
var je5 = parseFloat($("h_je5").value.trim());
var hl1 = parseFloat($("txt_hl1").value.trim());
var hl2 = parseFloat($("txt_hl2").value.trim());
var hl3 = parseFloat($("txt_hl3").value.trim());
var hl4 = parseFloat($("txt_hl4").value.trim());
var hl5 = parseFloat($("txt_hl5").value.trim());
var bb3 = $("ddl_bb3").value.trim();
$("txt_je5").value = je5;
$("txt_je3").value = round2((je1 * hl1 + je2 * hl2 - je4 * hl4 - je5 * hl5), 2);
if (bb3 == "USD") {
$("txt_je3").value = Div((je1 * hl1 + je2 * hl2 - je4 * hl4 - je5 * hl5), hl3, 2);
}
//$("ddl_bb5").value = "RMB";
//$("txt_hl5").value = "1.0000";
//$("txt_je5").value = "0.00";
}
}
function setSHOW() {
if ($("h_isSHOW").value.trim() == "0") {
$("h_isSHOW").value = "1";
document.getElementById('divSHOW').style.display = "";
initGrid3();
}
else if ($("h_isSHOW").value.trim() == "1") {
$("h_isSHOW").value = "0";
document.getElementById('divSHOW').style.display = "none";
}
}
//#region js计算函数
round2 = function (str, length) {
var r2 = parseFloat(str).toFixed(8);
var r1 = parseFloat(r2).toFixed(parseInt(length));
return r1;
}
//除法函数,用来得到精确的除法结果
//说明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) { }
try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
with (Math) {
r1 = Number(arg1.toString().replace(".", ""))
r2 = Number(arg2.toString().replace(".", ""))
return (r1 / r2) * pow(10, t2 - t1);
}
}
//给Number类型增加一个div方法调用起来更加方便。
Number.prototype.div = function (arg) {
return accDiv(this, arg);
}
//乘法函数,用来得到精确的乘法结果
//说明javascript的乘法结果会有误差在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
//调用accMul(arg1,arg2)
//返回值arg1乘以arg2的精确结果
function accMul(arg1, arg2) {
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
try { m += s1.split(".")[1].length } catch (e) { }
try { m += s2.split(".")[1].length } catch (e) { }
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
//给Number类型增加一个mul方法调用起来更加方便。
Number.prototype.mul = function (arg) {
return accMul(arg, this);
}
//加法函数,用来得到精确的加法结果
//说明javascript的加法结果会有误差在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
//调用accAdd(arg1,arg2)
//返回值arg1加上arg2的精确结果
function accAdd(arg1, arg2) {
var r1, r2, m;
try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
m = Math.pow(10, Math.max(r1, r2))
return (arg1 * m + arg2 * m) / m
}
//给Number类型增加一个add方法调用起来更加方便。
Number.prototype.add = function (arg) {
return accAdd(arg, this);
}
//加
function Add(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).add(parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
//减
function Cut(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).add(parseFloat(0) - parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
//乘
function Mul(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).mul(parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
//连乘
function Mul3(a, b, c, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = (parseFloat(a).mul(parseFloat(b)).mul(parseFloat(c))).toFixed(parseInt(length));
return parseFloat(_r);
}
//除
function Div(a, b, length) {
if ((typeof (length) == undefined) || (length == null)) {
length = 2;
}
var _r = parseFloat(a).div(parseFloat(b)).toFixed(parseInt(length));
return parseFloat(_r);
}
//#endregion