Question How do I use a decimal point in Javescript calculations?

RLGL

Platinum Member
Jan 8, 2013
2,114
321
126
Let me start by stating I know NOTHING about programming or what I am trying to do.
The editor I am using is Foxit Phantom PDF.
I am trying to utilize Javescript in a PDF form to perform simple calculations, dollars and cents. When adding all is good. Subtracting is another story, the result is a number with 14 positions after the decimal point. How do I restrict the result to 2 decimal points? The image is what I am using to create the calculations.

2019-04-22_14-40-10.png
 

RLGL

Platinum Member
Jan 8, 2013
2,114
321
126
A quick google search.

Just run this when you are displaying it.

https://www.w3schools.com/jsref/jsref_tofixed.asp
inserting the string :
var num = 5.56789;
var n = num.toFixed(2);
fill_0-Internal
results in:
[ Line: 00003 { TypeError } ] : Cannot read property 'value' of null

======== Field : calculate ========
[ Line: 00003 { TypeError } ] : Cannot read property 'value' of null

How do I fix it?

All the methods found by searching result in some sort of error.
 

MagnusTheBrewer

IN MEMORIAM
Jun 19, 2004
24,122
1,594
126
inserting the string :
var num = 5.56789;
var n = num.toFixed(2);
fill_0-Internal
results in:
[ Line: 00003 { TypeError } ] : Cannot read property 'value' of null

======== Field : calculate ========
[ Line: 00003 { TypeError } ] : Cannot read property 'value' of null

How do I fix it?

All the methods found by searching result in some sort of error.
You don't have to worry about decimal places until it's displayed.
 

purbeast0

No Lifer
Sep 13, 2001
53,492
6,333
126
inserting the string :
var num = 5.56789;
var n = num.toFixed(2);
fill_0-Internal
results in:
[ Line: 00003 { TypeError } ] : Cannot read property 'value' of null

======== Field : calculate ========
[ Line: 00003 { TypeError } ] : Cannot read property 'value' of null

How do I fix it?

All the methods found by searching result in some sort of error.
I'm not sure why your fill_0-Internal function is throwing an erro.

You asked about setting precision in numbers which is what the solution I posted is for.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,585
4,495
75
If you need to keep it a number, you can try rounding.

But it's hard to know how much of ECMAScript that PDF software actually supports.
 

RLGL

Platinum Member
Jan 8, 2013
2,114
321
126
Thanks for the input, I found another section of options that allowed the control of the decimal places.