Browse Source

数值四舍五入逻辑简单调整

TonyKang 5 years ago
parent
commit
d5faac9a51
1 changed files with 5 additions and 3 deletions
  1. 5 3
      app/reports/rpt_component/helper/jpc_helper_common_output.js

+ 5 - 3
app/reports/rpt_component/helper/jpc_helper_common_output.js

@@ -7,6 +7,7 @@ const REG2 = new RegExp('\r\n', 'g');
 const REG3 = new RegExp('\n', 'g');
 const REG3 = new RegExp('\n', 'g');
 const REG4 = new RegExp('\r', 'g');
 const REG4 = new RegExp('\r', 'g');
 const REG5 = new RegExp('\t', 'g');
 const REG5 = new RegExp('\t', 'g');
+const OFFSET_FLOAT = 0.0000000001;
 
 
 const JpcCommonOutputHelper = {
 const JpcCommonOutputHelper = {
     createCommonOutputWithoutDecorate: function(node, value, forceCombine) {
     createCommonOutputWithoutDecorate: function(node, value, forceCombine) {
@@ -57,10 +58,11 @@ const JpcCommonOutputHelper = {
     },
     },
     formatCell: function(formatStr, rstCell) {
     formatCell: function(formatStr, rstCell) {
         if (formatStr) {
         if (formatStr) {
-            if (!(isNaN(parseFloat(rstCell[JV.PROP_VALUE])))) {
+            const rstCellFloatVal = parseFloat(rstCell[JV.PROP_VALUE]);
+            if (!(isNaN(rstCellFloatVal))) {
                 const dotIdx = formatStr.indexOf('.');
                 const dotIdx = formatStr.indexOf('.');
                 if (dotIdx >= 0) {
                 if (dotIdx >= 0) {
-                    let tmpStr = parseFloat(rstCell[JV.PROP_VALUE]).toFixed(formatStr.length - dotIdx - 1);
+                    let tmpStr = (rstCellFloatVal + OFFSET_FLOAT).toFixed(formatStr.length - dotIdx - 1);
                     const digStr = formatStr.substr(dotIdx + 1, formatStr.length - dotIdx);
                     const digStr = formatStr.substr(dotIdx + 1, formatStr.length - dotIdx);
                     for (let sIdx = digStr.length - 1; sIdx >= 0; sIdx--) {
                     for (let sIdx = digStr.length - 1; sIdx >= 0; sIdx--) {
                         if (digStr[sIdx] === '#') {
                         if (digStr[sIdx] === '#') {
@@ -76,7 +78,7 @@ const JpcCommonOutputHelper = {
                     if (tmpStr[tmpStr.length - 1] === '.') tmpStr = tmpStr.substr(0, tmpStr.length - 1);
                     if (tmpStr[tmpStr.length - 1] === '.') tmpStr = tmpStr.substr(0, tmpStr.length - 1);
                     rstCell[JV.PROP_VALUE] = tmpStr;
                     rstCell[JV.PROP_VALUE] = tmpStr;
                 } else {
                 } else {
-                    rstCell[JV.PROP_VALUE] = parseFloat(rstCell[JV.PROP_VALUE]).toFixed(0);
+                    rstCell[JV.PROP_VALUE] = (rstCellFloatVal + OFFSET_FLOAT).toFixed(0);
                 }
                 }
                 const commaIdx = formatStr.indexOf(',');
                 const commaIdx = formatStr.indexOf(',');
                 if (commaIdx >= 0) {
                 if (commaIdx >= 0) {