Skip to main content
Known Participant
January 8, 2025
Answered

Calculation won't work with digits when opened in browser

  • January 8, 2025
  • 2 replies
  • 1029 views

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? 

Correct answer Nesa Nurani

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);

2 replies

Bernd Alheit
Community Expert
Community Expert
January 8, 2025

You will get NaN when n is zero.

Known Participant
January 8, 2025

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. 

Bernd Alheit
Community Expert
Community Expert
January 8, 2025

Emter: 158.59

Nesa Nurani
Community Expert
Community Expert
January 8, 2025

Browsers may not have full support for scripts.

Known Participant
January 8, 2025

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.