当金额以.d0结尾时,scrip会丢一分钱 [英] scrip drops a penny when amount ends with .d0

查看:70
本文介绍了当金额以.d0结尾时,scrip会丢一分钱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我调用一个函数,它将订购的单价和数量设为

创建金额......它看起来像这样。


函数calculateCost ()

{

quantity = document.RFO.quantity.value;

unitPrice = document.RFO.unitPrice.value;

total = 0;

if(isPositiveInteger(quantity))

{

quantity = parseFloat(quantity)

{

总=数量* unitPrice;

}

}

document.RFO。 total.value =格式(总计)

}


如果一个人输入以.10,.20,.30,...结尾的单价。,。90,

我的代码总共减少了一分钱?但是,如果价格以.1,

..2,.3,...,。9结尾,我的代码工作正常。

似乎计算有问题价格以0结尾,除非是.00

I call a function that takes the unit price and quantity ordered to
create an amount...it looks something like this.

function calculateCost()
{
quantity=document.RFO.quantity.value;
unitPrice=document.RFO.unitPrice.value;
total=0;
if(isPositiveInteger(quantity))
{
quantity=parseFloat(quantity)
{
total=quantity * unitPrice;
}
}
document.RFO.total.value=format(total)
}

if a person enters a unit price that ends with .10, .20, .30, ..., .90,
my code drops a penny off the total? However if the price ends with .1,
..2, .3, ..., .9, my code works fine.
Seems it has a problem calculating prices ending with 0 unless it''s .00

推荐答案


ey **** @ ncsa.uiuc.edu 写道:
如果一个人输入以.10,.20结尾的单价,.30,...,。90,
我的代码总共减少了一分钱?但是,如果价格以.1,
。,。3,...,。9结尾,我的代码工作正常。
似乎计算价格以0结尾的问题,除非它是' .00
if a person enters a unit price that ends with .10, .20, .30, ..., .90,
my code drops a penny off the total? However if the price ends with .1,
.2, .3, ..., .9, my code works fine.
Seems it has a problem calculating prices ending with 0 unless it''s .00




< http://www.jibbering.com/faq/#FAQ4_6>



<http://www.jibbering.com/faq/#FAQ4_6>

为什么我需要将数字转换为字符串?

Why would I need to convert a number into a string?


ey **** @ ncsa.uiuc.edu 写道:
为什么我需要将数字转换为字符串?
Why would I need to convert a number into a string?




你为什么想知道?


引用,请!



Why do you want to know?

Quote, please!


这篇关于当金额以.d0结尾时,scrip会丢一分钱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆