ASP和Javascript中取整函数的应用
来源:asp之家 时间:2009-06-07 18:38:00
朋友的网站要计算机票的折扣价格,并且在最后的折扣价格上应对个位进行四舍五入,同时在ASP和Javascript代码中都需要实现这个功能,他们的操作并不一样:
ASP中实现四舍五入:
tmpAmount=tree_Cart.getItemInt(tCart.getItem("p_id"))
tmpPriceCurrent=int((cp.toProductPrice(tCart.getItemNum("p_price"),tCart.getItemInt("p_discount"))/10)+0.5)*10
tmpPrices=tmpPriceCurrent*tmpAmount
int(N)可以实现取整,而要四舍五入的话,int(N+0.5)可以实现。由于这里是要将个位数四舍五入,因此,先将原来的数值除以10,四舍五入后再乘以10就可以了。
Javascript中实现四舍五入:
由于Javascript中没有int函数,而是用Math.round(N)来实现:
appShop.toProductDiscountPrice=function(strPrice,strDiscount)
{
if (!dcs.common.isNumber(strDiscount)) strDiscount=100;
var re=Math.round((strPrice*strDiscount/100)/10)*10;
re=dcs.codes.toPrice(re);
return re;
}
Math.round(N)是Javascript的四舍五入函数,为了实现个位数的四舍五入,我们先将原来的数值除以10,四舍五入之后再乘以10就可以了。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL 5.7增强版Semisync Replication性能优化
![](https://img.aspxhome.com/file/2023/8/124858_0s.jpg)
SQLServer 优化SQL语句 in 和not in的替代方案
XML编程实例:用ASP+XML打造留言本
Pytorch抽取网络层的Feature Map(Vgg)实例
Go语言包和包管理详解
Python学习之asyncore模块用法实例教程
在Python中操作文件之seek()方法的使用教程
支持python的分布式计算框架Ray详解
![](https://img.aspxhome.com/file/2023/2/102912_0s.jpg)
Python脚本处理空格的方法
![](https://img.aspxhome.com/file/2023/6/84106_0s.png)
asp form 表单验证函数
python实现基于信息增益的决策树归纳
巧用Dreamweaver4文件库更新网站
![](https://img.aspxhome.com/file/UploadPic/20072/200723113133681s.gif)
Python中异常捕获与处理的方法总结
![](https://img.aspxhome.com/file/2023/8/95898_0s.png)
asp 删除数据并同时删除图片的代码
python turtle库画圣诞树详细代码教程
![](https://img.aspxhome.com/file/2023/4/97354_0s.png)
JavaScript 实现的 zip 压缩和解压缩工具包Zip.js使用详解
![](https://img.aspxhome.com/file/2023/5/136065_0s.png)
利用python在excel里面直接使用sql函数的方法
![](https://img.aspxhome.com/file/2023/1/81781_0s.jpg)
Python遍历文件夹和读写文件的实现方法
![](https://img.aspxhome.com/file/2023/4/66414_0s.jpg)
Python3.9新特性详解
![](https://img.aspxhome.com/file/2023/6/79426_0s.png)