Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(float calculate bug): fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
DR-Univer committed Sep 24, 2020
1 parent 789bab5 commit ef2a96a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 43 deletions.
91 changes: 56 additions & 35 deletions src/function/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp[m][n]) && isRealNum(tp[m][n])){
value = parseFloat(fp[m][n]) * parseFloat(tp[m][n]);
value = luckysheet_calcADPMM(fp[m][n], sp, tp[p][n]);//parseFloat(fp[m][n]) * parseFloat(tp[m][n]);
}
else{
value = error.v;
Expand All @@ -217,7 +217,7 @@ function luckysheet_compareWith() {
tp[p][n] = booleanToNum(tp[p][n]);

if(isRealNum(fp[m][p]) && isRealNum(tp[p][n])){
value += parseFloat(fp[m][p]) * parseFloat(tp[p][n]);
value += luckysheet_calcADPMM(fp[m][p], sp, tp[p][n]);//parseFloat(fp[m][p]) * parseFloat(tp[p][n]);
}
else{
value += error.v;
Expand Down Expand Up @@ -249,7 +249,7 @@ function luckysheet_compareWith() {
tp[m][p] = booleanToNum(tp[m][p]);

if(isRealNum(tp[m][p]) && isRealNum(fp[p][n])){
value += parseFloat(tp[m][p]) * parseFloat(fp[p][n]);
value += luckysheet_calcADPMM(fp[p][n], sp, tp[m][p]);//parseFloat(tp[m][p]) * parseFloat(fp[p][n]);
}
else{
value += error.v;
Expand Down Expand Up @@ -282,7 +282,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp[m][n]) && isRealNum(tp[n])){
value = parseFloat(fp[m][n]) * parseFloat(tp[n]);
value = luckysheet_calcADPMM(fp[m][n], sp, tp[n]);//parseFloat(fp[m][n]) * parseFloat(tp[n]);
}
else{
value = error.v;
Expand All @@ -307,7 +307,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp[m][0]) && isRealNum(tp[n])){
value = parseFloat(fp[m][0]) * parseFloat(tp[n]);
value = luckysheet_calcADPMM(fp[m][0], sp, tp[n]);// parseFloat(fp[m][0]) * parseFloat(tp[n]);
}
else{
value = error.v;
Expand Down Expand Up @@ -335,7 +335,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp[n]) && isRealNum(tp[m][n])){
value = parseFloat(fp[n]) * parseFloat(tp[m][n]);
value = luckysheet_calcADPMM(fp[n], sp, tp[m][n]);// parseFloat(fp[n]) * parseFloat(tp[m][n]);
}
else{
value = error.v;
Expand All @@ -360,7 +360,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp[n]) && isRealNum(tp[m][0])){
value = parseFloat(fp[n]) * parseFloat(tp[m][0]);
value = luckysheet_calcADPMM(fp[n], sp, tp[m][0]);//parseFloat(fp[n]) * parseFloat(tp[m][0]);
}
else{
value = error.v;
Expand Down Expand Up @@ -388,7 +388,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp[n]) && isRealNum(tp[n])){
value = parseFloat(fp[n]) * parseFloat(tp[n]);
value = luckysheet_calcADPMM(fp[n], sp, tp[n]);// parseFloat(fp[n]) * parseFloat(tp[n]);
}
else{
value = error.v;
Expand All @@ -414,7 +414,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp[m][n]) && isRealNum(tp)){
value = parseFloat(fp[m][n]) * parseFloat(tp);
value = luckysheet_calcADPMM(fp[m][n], sp, tp);// parseFloat(fp[m][n]) * parseFloat(tp);
}
else{
value = error.v;
Expand All @@ -432,7 +432,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp[n]) && isRealNum(tp)){
value = parseFloat(fp[n]) * parseFloat(tp);
value = luckysheet_calcADPMM(fp[n], sp, tp);// parseFloat(fp[n]) * parseFloat(tp);
}
else{
value = error.v;
Expand All @@ -458,7 +458,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp) && isRealNum(tp[m][n])){
value = parseFloat(fp) * parseFloat(tp[m][n]);
value = luckysheet_calcADPMM(fp, sp, tp[m][n]);// parseFloat(fp) * parseFloat(tp[m][n]);
}
else{
value = error.v;
Expand All @@ -476,7 +476,7 @@ function luckysheet_compareWith() {

let value;
if(isRealNum(fp) && isRealNum(tp[n])){
value = parseFloat(fp) * parseFloat(tp[n]);
value = luckysheet_calcADPMM(fp, sp, tp[n]);//parseFloat(fp) * parseFloat(tp[n]);
}
else{
value = error.v;
Expand All @@ -494,7 +494,7 @@ function luckysheet_compareWith() {

let result;
if(isRealNum(fp) && isRealNum(tp)){
result = parseFloat(fp) * parseFloat(tp);
result = luckysheet_calcADPMM(fp, sp, tp);//parseFloat(fp) * parseFloat(tp);
}
else{
result = error.v;
Expand Down Expand Up @@ -523,7 +523,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp[m][n]) / parseFloat(tp[m][n]);
value = luckysheet_calcADPMM(fp[m][n], sp, tp[m][n]);// parseFloat(fp[m][n]) / parseFloat(tp[m][n]);
}
}
else{
Expand Down Expand Up @@ -553,7 +553,7 @@ function luckysheet_compareWith() {
tp_inverse[p][n] = booleanToNum(tp_inverse[p][n]);

if(isRealNum(fp[m][p]) && isRealNum(tp_inverse[p][n])){
value += parseFloat(fp[m][p]) * parseFloat(tp_inverse[p][n]);
value += luckysheet_calcADPMM(fp[m][p], "*", tp_inverse[p][n]);// parseFloat(fp[m][p]) * parseFloat(tp_inverse[p][n]);
}
else{
value += error.v;
Expand Down Expand Up @@ -590,7 +590,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp[m][n]) / parseFloat(tp[n]);
value = luckysheet_calcADPMM(fp[m][n], sp, tp[n]);// parseFloat(fp[m][n]) / parseFloat(tp[n]);
}
}
else{
Expand Down Expand Up @@ -620,7 +620,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp[m][0]) / parseFloat(tp[n]);
value = luckysheet_calcADPMM(fp[m][0], sp, tp[n]);// parseFloat(fp[m][0]) / parseFloat(tp[n]);
}
}
else{
Expand Down Expand Up @@ -653,7 +653,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp[n]) / parseFloat(tp[m][n]);
value = luckysheet_calcADPMM(fp[n], sp, tp[m][n]);//parseFloat(fp[n]) / parseFloat(tp[m][n]);
}
}
else{
Expand Down Expand Up @@ -683,7 +683,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp[n]) / parseFloat(tp[m][0]);
value = luckysheet_calcADPMM(fp[n], sp, tp[m][0]);//parseFloat(fp[n]) / parseFloat(tp[m][0]);
}
}
else{
Expand Down Expand Up @@ -716,7 +716,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp[n]) / parseFloat(tp[n]);
value = luckysheet_calcADPMM(fp[n], sp, tp[n]);//parseFloat(fp[n]) / parseFloat(tp[n]);
}
}
else{
Expand Down Expand Up @@ -747,7 +747,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp[m][n]) / parseFloat(tp);
value = luckysheet_calcADPMM(fp[m][n], sp, tp);//parseFloat(fp[m][n]) / parseFloat(tp);
}
}
else{
Expand All @@ -770,7 +770,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp[n]) / parseFloat(tp);
value = luckysheet_calcADPMM(fp[n], sp, tp);//parseFloat(fp[n]) / parseFloat(tp);
}
}
else{
Expand Down Expand Up @@ -801,7 +801,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp) / parseFloat(tp[m][n]);
value = luckysheet_calcADPMM(fp, sp, tp[m][n]);//parseFloat(fp) / parseFloat(tp[m][n]);
}
}
else{
Expand All @@ -824,7 +824,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = parseFloat(fp) / parseFloat(tp[n]);
value = luckysheet_calcADPMM(fp, sp, tp[n]);//parseFloat(fp) / parseFloat(tp[n]);
}
}
else{
Expand All @@ -847,7 +847,7 @@ function luckysheet_compareWith() {
result = error.d;
}
else{
result = parseFloat(fp) / parseFloat(tp);
result = luckysheet_calcADPMM(fp, sp, tp);//parseFloat(fp) / parseFloat(tp);
}
}
else{
Expand Down Expand Up @@ -879,7 +879,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = eval(parseFloat(fp[m][n]) + sp + parseFloat(tp[m][n]));
value = luckysheet_calcADPMM(fp[m][n], sp, tp[m][n]);// eval(parseFloat(fp[m][n]) + sp + parseFloat(tp[m][n]));
}
}
else{
Expand Down Expand Up @@ -910,7 +910,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = eval(parseFloat(fp[m][n]) + sp + parseFloat(tp[n]));
value = luckysheet_calcADPMM(fp[m][n], sp, tp[n]);//eval(parseFloat(fp[m][n]) + sp + parseFloat(tp[n]));
}
}
else{
Expand Down Expand Up @@ -941,7 +941,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = eval(parseFloat(fp[n]) + sp + parseFloat(tp[m][n]));
value = luckysheet_calcADPMM(fp[n], sp, tp[m][n]);//eval(parseFloat(fp[n]) + sp + parseFloat(tp[m][n]));
}
}
else{
Expand Down Expand Up @@ -969,7 +969,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = eval(parseFloat(fp[n]) + sp + "(" + parseFloat(tp[n]) + ")" );
value = luckysheet_calcADPMM(fp[n], sp, tp[n]);//eval(parseFloat(fp[n]) + sp + "(" + parseFloat(tp[n]) + ")" );
}
}
else{
Expand Down Expand Up @@ -1000,7 +1000,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = eval(parseFloat(fp[m][n]) + sp + parseFloat(tp));
value = luckysheet_calcADPMM(fp[m][n], sp, tp);//eval(parseFloat(fp[m][n]) + sp + parseFloat(tp));
}
}
else{
Expand All @@ -1023,7 +1023,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = eval(parseFloat(fp[n]) + sp + parseFloat(tp));
value = luckysheet_calcADPMM(fp[n], sp, tp);//eval(parseFloat(fp[n]) + sp + parseFloat(tp));
}
}
else{
Expand Down Expand Up @@ -1054,7 +1054,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = eval(parseFloat(fp) + sp + parseFloat(tp[m][n]));
value = luckysheet_calcADPMM(fp, sp, tp[m][n]);//eval(parseFloat(fp) + sp + parseFloat(tp[m][n]));
}
}
else{
Expand All @@ -1077,7 +1077,7 @@ function luckysheet_compareWith() {
value = error.d;
}
else{
value = eval(parseFloat(fp) + sp + parseFloat(tp[n]));
value = luckysheet_calcADPMM(fp, sp, tp[n]);//eval(parseFloat(fp) + sp + parseFloat(tp[n]));
}
}
else{
Expand All @@ -1100,7 +1100,7 @@ function luckysheet_compareWith() {
result = error.d;
}
else{
result = eval(parseFloat(fp) + sp + "(" + parseFloat(tp) + ")");
result = luckysheet_calcADPMM(fp, sp, tp);//eval(parseFloat(fp) + sp + "(" + parseFloat(tp) + ")");
}
}
else{
Expand Down Expand Up @@ -1568,6 +1568,26 @@ function luckysheet_getarraydata() {
return arr;
}

function luckysheet_calcADPMM(fp, sp, tp){
let value;
if(sp=="+"){
value = numeral(fp).add(tp).value();
}
else if(sp=="-"){
value = numeral(fp).subtract(tp).value();
}
else if(sp=="%"){
value = eval(parseFloat(fp) + sp+ "(" + parseFloat(tp) + ")");
}
else if(sp=="/"){
value = numeral(fp).divide(tp).value();
}
else if(sp=="*"){
value = numeral(fp).multiply(tp).value();
}
return value;
}

function luckysheet_getcelldata(txt) {
if (window.luckysheet_getcelldata_cache == null) {
window.luckysheet_getcelldata_cache = {};
Expand Down Expand Up @@ -1881,5 +1901,6 @@ export {
luckysheet_getValue,
luckysheet_indirect_check,
luckysheet_indirect_check_return,
luckysheet_offset_check
luckysheet_offset_check,
luckysheet_calcADPMM
}
12 changes: 6 additions & 6 deletions src/function/functionImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const functionImplementation = {
continue;
}

sum += parseFloat(dataArr[i]);
sum = luckysheet_calcADPMM(sum, "+", dataArr[i]);// parseFloat(dataArr[i]);
}
}

Expand Down Expand Up @@ -143,15 +143,15 @@ const functionImplementation = {
return formula.error.v;
}

sum += parseFloat(dataArr[i]);
sum = luckysheet_calcADPMM(sum, "+", dataArr[i]);// parseFloat(dataArr[i]);
count++;
}

if(count == 0){
return formula.error.d;
}

return sum / count;
return luckysheet_calcADPMM(sum, "/", count);// sum / count;
}
catch (e) {
var err = e;
Expand Down Expand Up @@ -1746,7 +1746,7 @@ const functionImplementation = {
continue;
}

sum += parseFloat(sumRangeData[i]);
sum = luckysheet_calcADPMM(sum, "+", sumRangeData[i]);// parseFloat(sumRangeData[i]);
}
}
}
Expand All @@ -1760,7 +1760,7 @@ const functionImplementation = {
continue;
}

sum += parseFloat(v);
sum = luckysheet_calcADPMM(sum, "", v);// parseFloat(v);
}
}
}
Expand Down Expand Up @@ -4613,7 +4613,7 @@ const functionImplementation = {

for(var i = 0; i < rangeData.length; i++){
if(results[i]){
sum += parseFloat(rangeData[i]);
sum = luckysheet_calcADPMM(sum, "+", rangeData[i]); //parseFloat(rangeData[i]);
}
}

Expand Down
Loading

0 comments on commit ef2a96a

Please sign in to comment.