Skip to main content
Participating Frequently
April 20, 2020
Question

Modulo on long numbers

  • April 20, 2020
  • 1 reply
  • 826 views

Is there any bug in the Java Script Modulo?

I have to add to my form validation of an account number. The problem is that it is validating by modulo of 30 digits number. I did everything right but it came out that my accounts were wrong. Each one. So I checked one by one and looks like modulo is broken after reaching 24 digits.

Just check this validation script:

 

app.alert("10 digits - "+1000000000%10);
app.alert("20 digits - "+10000000000000000000%10);
app.alert("21 digits - "+100000000000000000000%10);
app.alert("22 digits - "+1000000000000000000000%10);
app.alert("23 digits - "+10000000000000000000000%10);
app.alert("24 digits - "+100000000000000000000000%10);

 

Any idea how to bypass that? I can't do anything else besides modulo by 97 to validate bank account.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
April 20, 2020

This is a limitation of the core JS language. Read this for more information:

https://www.w3schools.com/js/js_numbers.asp

rospondekAuthor
Participating Frequently
April 20, 2020

So no way to change the type to bigint or any other long number?

I'm trying to find anything but without any luck so far. There has to be a way cause I saw some forms which did that validation without problems.

try67
Community Expert
Community Expert
April 20, 2020

Are you sure the modulo needs to be done on the entire number? Can you post the instructions for it?

 

There is a BigInt object in JS but it was introduced in later versions. It might work in Acrobat/Reader DC, but not in earlier versions of the application.