首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >为什么我的index.js代码没有办法计算出我最后要求计算出来的结果?

为什么我的index.js代码没有办法计算出我最后要求计算出来的结果?

提问于 2023-06-09 18:31:21
回答 0关注 0查看 89

我的代码如下,不知道为什么最后的FinalexpectedPaybackTime结果始终无法自动计算出来,特此求助,感谢帮助。

// index.js

// 获取小程序实例

const app = getApp();

Page({

  data: {

    showInputModal: false,

    inputModalTitle: '',

    inputValue: '',

    inputType: 'text',

    inputCallback: null,

    maintenanceFee: 0,

    operatorCost: 0,

    immunohistochemistryGrowthRate: 0,

    detectionSystemPrice: 0,

    detectionSystemCost: 0,

    dailySlideCount: 0,

    exchangeRate: 0,

    instrumentPriceUSD: 0,

    menuItems: ['无','BOND 试剂政策', '2023 BOND 政策', 'BOND 试剂政策+2023 BOND 政策'], // 下拉菜单选项

    selectedMenuItem: '', // 当前选择的选项

    isMenuOpen: false, // 下拉菜单是否打开

    finalexpectedPaybackTime: 0,

    machineDiscount: 0,

},

toggleMenu : function () {

this.setData({

      isMenuOpen: !this.data.isMenuOpen

});

},

selectMenuItem: function (e) {

const { value } = e.currentTarget.dataset;

this.setData({ selectedMenuItem: value, isMenuOpen: false

});

},

onInputModalCancel() {

this.setData({ showInputModal: false });

},

onInputModalConfirm() {

this.data.inputCallback(this.data.inputValue);

this.setData({ showInputModal: false });

},

onInputChange(e) {

this.setData({ inputValue: e.detail.value });

},

instrumentPriceUSDInput: function (e) {

const instrumentPriceUSD = parseFloat(e.detail.value);

this.setData({ instrumentPriceUSD: instrumentPriceUSD });

this.calculateResults();

},

machineDiscountInput: function (e) {

const machineDiscount = parseFloat(e.detail.value);

this.setData({ machineDiscount: machineDiscount });

this.calculateResults();

},

dailySlideCountInput: function (e) {

const dailySlideCount = parseFloat(e.detail.value);

this.setData({ dailySlideCount: dailySlideCount });

this.calculateResults();

},

detectionSystemCostInput: function (e) {

const detectionSystemCost = parseFloat(e.detail.value);

this.setData({ detectionSystemCost: detectionSystemCost });

this.calculateResults();

},

detectionSystemPriceInput: function (e) {

const detectionSystemPrice = parseFloat(e.detail.value);

this.setData({ detectionSystemPrice: detectionSystemPrice });

this.calculateResults();

},

immunohistochemistryGrowthRateInput: function (e) {

const immunohistochemistryGrowthRate = parseFloat(e.detail.value);

this.setData({ immunohistochemistryGrowthRate: immunohistochemistryGrowthRate });

this.calculateResults();

},

operatorCostInput: function (e) {

const operatorCost = parseFloat(e.detail.value);

this.setData({ operatorCost: operatorCost });

this.calculateResults();

},

maintenanceFeeInput: function (e) {

const maintenanceFee = parseFloat(e.detail.value);

this.setData({ maintenanceFee: maintenanceFee });

this.calculateResults();

},

exchangeRateInput: function (e) {

const { value } = e.detail;

// 使用正则表达式替换输入值,只保留数字和小数点,并限制小数点后两位

const formattedValue = value.replace(/[^\d.]/g, '').replace(/\.(?=.*\.)/g, '').slice(0, 5);

this.setData({ exchangeRate: formattedValue });

},

calculateResults: function () {

const {

instrumentPriceUSD,

machineDiscount,

exchangeRate,

dailySlideCount,

immunohistochemistryGrowthRate,

maintenanceFee,

operatorCost,

detectionSystemPrice,

detectionSystemCost,

selectedMenuItem,

} = this.data;

const instrumentPriceRMB = instrumentPriceUSD * exchangeRate;

const instrumentPriceWithDiscount = instrumentPriceRMB * (1 - machineDiscount / 100);

const detectionSystemRev = detectionSystemPrice-detectionSystemCost;

const annualSlideCount = dailySlideCount * 21.75 * 12;

const FirstreturnUnits = Math.floor((annualSlideCount / 600) * 200);

const FIRSTexpectedPaybackTime = (instrumentPriceWithDiscount+maintenanceFee+operatorCost*2)/(((annualSlideCount*detectionSystemRev)+ ((annualSlideCount * (1+immunohistochemistryGrowthRate)-FirstreturnUnits) *detectionSystemRev))+FirstreturnUnits*detectionSystemRev);

if (selectedMenuItem === 'BOND 试剂政策') {

let SECONDexpectedPaybackTime = FIRSTexpectedPaybackTime;

const SecondreturnUnits = Math.floor((annualSlideCount * (1+immunohistochemistryGrowthRate) / 600) * 200);

while (SECONDexpectedPaybackTime > 1) {

SECONDexpectedPaybackTime = instrumentPriceWithDiscount + maintenanceFee + operatorCost * 2 -((annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate)) - SecondreturnUnits) * detectionSystemRev + SecondreturnUnits * detectionSystemPrice / ((annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate)) - SecondreturnUnits) * detectionSystemRev + SecondreturnUnits * detectionSystemPrice;

const ThirdreturnUnits = Math.floor((annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate)/ 600 * 200));

let ThirdexpectedPaybackTime = SECONDexpectedPaybackTime;

while (ThirdexpectedPaybackTime > 1) {

ThirdexpectedPaybackTime = ((annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate)) - SecondreturnUnits) * detectionSystemRev + SecondreturnUnits * detectionSystemPrice-((annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate)) - SecondreturnUnits) * detectionSystemRev - SecondreturnUnits * detectionSystemPrice + maintenanceFee + operatorCost / (annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate) - ThirdreturnUnits) * detectionSystemRev + ThirdreturnUnits * detectionSystemPrice;

const FourthreturnUnits = Math.floor((annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate)* (1 + immunohistochemistryGrowthRate) / 600 * 200));

let FourthexpectedPaybackTime = ThirdexpectedPaybackTime;

while (FourthexpectedPaybackTime > 1) {

FourthexpectedPaybackTime = ((annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate)) - SecondreturnUnits) * detectionSystemRev + SecondreturnUnits * detectionSystemPrice-((annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate)) - SecondreturnUnits) * detectionSystemRev - SecondreturnUnits * detectionSystemPrice + maintenanceFee + operatorCost-(annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate) - ThirdreturnUnits) * detectionSystemRev - ThirdreturnUnits * detectionSystemPrice + maintenanceFee + operatorCost / (annualSlideCount * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate) * (1 + immunohistochemistryGrowthRate) - FourthreturnUnits) * detectionSystemRev + FourthreturnUnits * detectionSystemPrice;

if (SECONDexpectedPaybackTime < 1) {

FinalexpectedPaybackTime = 2 + SECONDexpectedPaybackTime * 12;

} else if (ThirdexpectedPaybackTime < 1) {

FinalexpectedPaybackTime = 3 + ThirdexpectedPaybackTime * 12;

} else if (FourthexpectedPaybackTime < 1) {

FinalexpectedPaybackTime = 4 + FourthexpectedPaybackTime * 12;

}

this.setData({

                   FinalexpectedPaybackTime: FinalexpectedPaybackTime

});

}

}

}

}

}

});

回答

成为首答用户。去 写回答
相关文章
js计算出来的文件md5值跟java计算出来的不一致
最近在项目中遇到了大文件分割上传问题,为了保证上传的文件的有效性需要确保分割的文件上传首先要成功,因此用到了md5加密,在js代码中上传文件之前将要上传的文件内容进行md5加密,然后作为其中一个参数传到后端服务器,后端再收到文件后对文件进行同样的md5加密,然后将两个md5值对比,验证成功则人为文件分割块是正确的,然后保存,但是却遇到一个问题:
johnhuster的分享
2022/03/28
3.7K0
#PY小贴士# 我的PyCharm为什么执行结果很诡异?
今天讲的这个小问题,没有用过 PyCharm 的同学会完全不知所云,但用过的人,可能有一半以上概率会遇到这个算不上 bug 但也可能让人迷惑的坑。
Crossin先生
2020/01/20
1.3K0
#PY小贴士# 我的PyCharm为什么执行结果很诡异?
我为什么晚上写代码?
摘要:作为一个有点追求的程序员,应该每天练习写代码,而夜深人静的时候,似乎比较合适,至少对我来说是这样。
Fundebug
2019/12/31
6140
对象检测网络中的mAP到底怎么计算出来的
mAP是英文mean Average Precision的全称,同时也是衡量深度学习中对象检测算法准确率的一个重要指标,mAP的计算涉及到很多专业的术语与解释,首先就来认识一下这些术语名词与解释:
OpenCV学堂
2018/10/23
2.5K0
对象检测网络中的mAP到底怎么计算出来的
面试的时候我只会聊项目,结果就把我挂了!
在上周,我密集面试了若干位Java后端的候选人,工作经验在3到5年间。我的标准其实不复杂:第一能干活,第二Java基础要好,第三最好熟悉些分布式框架。我相信其它公司招初级开发时,应该也照着这个标准来面的。
田维常
2019/07/16
5820
面试的时候我只会聊项目,结果就把我挂了!
我学编程时最后悔的事!
很多朋友看完这篇文章后,会感到好奇:我是如何在大学期间做了那么多事情、学了那么多编程知识的?
程序员鱼皮
2021/07/23
5010
我的代码日程
我的代码日程
Java架构师必看
2021/08/03
5830
为什么我写不出面向对象的代码
举个栗子,比如之前项目组做的付款业务,这里面包含了A付款,B付款,C付款,D付款等模块。
Lvshen
2022/12/05
1.2K0
为什么我写不出面向对象的代码
为什么我的BERT不行?
这节只列举问题,思路放下一章。这里是给大家去定位问题的思路,通过这些渠道能发现一些问题,而不是对问题束手无策了。
lyhue1991
2023/02/23
1.3K0
为什么我的BERT不行?
妹子让我看她写的pytest,结果...
陆陆续续断更好久好久了,这么久发生了很多事情,也思考了很多事情。突然发现拖延症已经严重影响到了我。
Python攻城狮
2020/12/21
9170
谁在调试我的代码?
为了提高开发的软件产品安全性,大部分选择的方案防护方案是,通过用成熟的加固软件进行对自己研发的软件做防护,从而达到对软件搭建一个安全防护墙。加固软件主要做的两件事,对软件中关键代码的保护以及提高对软件逆向反编译的门槛。
小道安全
2021/12/13
6800
谁在调试我的代码?
我的代码简洁之道
https://juejin.cn/post/6903325147420164104
coder_koala
2021/10/18
7500
为什么if-else会影响我的代码的复杂度
我之前写了一篇文章《我用规则引擎消除if语句,提高了代码的可扩展性》,这篇文章我想阐述的观点是复杂的if语句可能会影响代码的阅读和代码的扩展性,会将非业务的条件逻辑与业务逻辑混合在一起。时间长了代码会越来越臃肿,因此这种情况下我推荐使用一些设计模式例如策略模式,责任链模式等去优化if语句带来的问题,文中我发现使用规则引擎也能实现类似效果,因此介绍了怎么使用规则引擎Easy Rules去取代if语句。
Lvshen
2022/05/05
1.5K0
为什么if-else会影响我的代码的复杂度
以太坊合约地址是怎么计算出来的?(附源码实现)
darren94me: https://learnblockchain.cn/people/4859
Tiny熊
2022/04/08
1.7K0
以太坊合约地址是怎么计算出来的?(附源码实现)
我为什么读博,以及我为什么不读博?
研究生三年后,毕业生都做出了自己的选择,一部分人就业,一部分人选择继续深造,不同的路径,同样的都是在探索自己的生涯之路。很多人都会比较一下毕业后直接工作和读博这三年内到底有何不同?下面就彻底晒晒。
用户3578099
2020/11/30
1.1K0
我为什么读博,以及我为什么不读博?
我写出这样干净的代码,老板直夸我
一份整洁的代码对于一个系统是多么重要。如果代码写的乱七八糟,最后的结果就是无法对这些代码进行有效的管控。很有可能会毁掉这个系统。
Lvshen
2022/05/05
3880
我写出这样干净的代码,老板直夸我
为什么我要写自己的框架?
其实说白了框架就是使用别人造好的轮子。在软件开发里面就是command+C/command+V。
哲洛不闹
2018/09/18
1.3K0
为什么我要写自己的框架?
点击加载更多

相似问题

R语言 分组计算出来的结果每组数值相同是为什么?

0188

A=481.66是怎么计算出来的?

2340

为什么我不符合要求?

1249

为什么我ping我不通我的内网?

3975

为什么我的Python代码输出的数据是竖着的?

0365
相关问答用户
腾讯云TDP | TDP会员擅长3个领域
到家集团 | 技术VP擅长5个领域
腾讯云TDP | KOL擅长5个领域
擅长4个领域
擅长3个领域
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文