Skip to main content
Known Participant
Jan 8, 2025 11:05 AM UTC
Answered

Calculation won't work with digits when opened in browser

I have a file with several calculations in - see attached file. 

But one calculation works only partly - the field 'Intervalløn beregnet'. 

 

The calculation-script is: 

var q = getField("Aftalt timeløn").value;
var n = getField("Reguleringsprocent").value;
event.value = q*1924/n;

 

'Aftalt Timeløn' is a field that can be filled with a number, format is a number with two digits. 

'Reguleringsprocent' is a field with a fixed numer, format number/no format, digit-seperater , or . (- none of these has made the soution for me) 

 

The problem:

The file works fine in Adboe (at least at my pc)

The file works fine in browser (Chrome), as long as the number filled in has no digits. 

The fault appears, if theres digits added in the number filled in - then the result just shows 'nan'

 

How can I get the field to work properly? 

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
Jan 8, 2025 3:13 PM UTC

Ok - I can see that it'll do the trick. 
But it's not me who shall put in the number - and here in Denmark no one use that format. 
Is there a way to make it accept the 158,59?

all other calculations work fine with the comma. 


Assuming you use comma as decimal point and no thousand separator as format, you can convert comma to dot in your script like this:

var q = this.getField("Aftalt timeløn").valueAsString.replace(",", ".");
var n = this.getField("Reguleringsprocent").valueAsString.replace(",", ".");

q = Number(q);
n = Number(n);

8 replies

Bernd Alheit
Community Expert
Community Expert
Jan 8, 2025 12:25 PM UTC

You will get NaN when n is zero.

Translate
Known Participant
Jan 8, 2025 12:28 PM UTC

But n is never zero. 
n is a fixed number - the calculation works if q = 159, but not if q = 158,59, so it makes no sense to me. 

Translate
Bernd Alheit
Community Expert
Community Expert
Jan 8, 2025 1:16 PM UTC

Emter: 158.59

Translate
Nesa Nurani
Community Expert
Community Expert
Jan 8, 2025 11:25 AM UTC

Browsers may not have full support for scripts.

Translate
Known Participant
Jan 8, 2025 11:45 AM UTC

Maybe not. 

But that doesn't explain why the script works without digtigs - but not with the digits. 

And all the other scripts in the form works fine - including digits. 

Translate