PDF 双值中的 JavaScript
我有以下代码,应该在 pdf 中进行求和。
var sum = 0.0;
var f1 = this.getField("price");
var temp = parseFloat(f1.value);
sum = temp;
var total = this.getField("total");
if(sum > 0)
{
total.value = sum;
}
else
{
total.value = "";
}
但如果输入是
18.31
我的总计是
18
编辑:我也尝试过
console.println(f1.value);
但f1.value的值只有18。
编辑:这是在<的javascript解释器中运行的href="http://www.foxitsoftware.com/pdf/reader_2/whatsnew23.htm" rel="nofollow noreferrer">foxit pdf 阅读器。
编辑:我已经确认 Foxit Reader javascript 解释器存在错误。
I have the following code that is supposed to do a sum in a pdf.
var sum = 0.0;
var f1 = this.getField("price");
var temp = parseFloat(f1.value);
sum = temp;
var total = this.getField("total");
if(sum > 0)
{
total.value = sum;
}
else
{
total.value = "";
}
But if the input is
18.31
my total is
18
EDIT: I also tried
console.println(f1.value);
But the value of f1.value is only 18.
EDIT: this is running in the javascript interpreter in the foxit pdf reader.
EDIT: I have confirmed there is a bug in the foxit reader javascript interpreter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
parseFloat()
将f1.value
(如果它是数字)转换为字符串,并根据toString() 的内容对其进行四舍五入
对象的方法返回。尝试没有它。
http://www.jibbering.com/faq/faq_notes/type_convert.html# tcParseFl
That's because
parseFloat()
convertsf1.value
(if it is a number) into a string, rounding it along the way, depending on what thetoString()
method of the object returns.Try without it.
http://www.jibbering.com/faq/faq_notes/type_convert.html#tcParseFl