Skip to main content
Participating Frequently
Apr 20, 2020 7:34 AM UTC
Question

Modulo on long numbers

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 is closed to new replies. Start a new post to keep the conversation going.

14 replies

try67
Community Expert
Community Expert
Apr 20, 2020 7:42 AM UTC

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

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

Translate
rospondekAuthor
Participating Frequently
Apr 20, 2020 9:27 AM UTC

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.

Translate
try67
Community Expert
Community Expert
Apr 20, 2020 9:34 AM UTC

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.

Translate