views:

156

answers:

1

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.

+1  A: 

That's because parseFloat() converts f1.value (if it is a number) into a string, rounding it along the way, depending on what the toString() method of the object returns.

Try without it.

http://www.jibbering.com/faq/faq_notes/type_convert.html#tcParseFl

Luca Matteis
Did you get what he is asking ? I do not understand the question.
Vijay Dev
I guess I should ask a new question.Why is a fields value truncated?
Milhous
Do you have a `maxlength` attribute set?
Luca Matteis
no, i can put 12345678.79 and I get 12345678
Milhous