0

I want to divide a huge Number by 97 in PHP.

My Number: 500105175408332501131480

In Java I used the Bigint Class but in PHP I cant. Its also important that I am working on a Sandbox Machine, so I'm not able to use Composer etc. pp.

(Im working on https://platform.entwicklerheld.de)

Is there a possability to divite such huge Numbers without using an Lib like this https://github.com/pear/Math_BigInteger/blob/trunk/demo/benchmark.php?

  • 1
    Can you use one of the [two core extensions for math](https://stackoverflow.com/a/211548/231316)? Sample here: https://3v4l.org/PPP2d – Chris Haas Aug 07 '21 at 18:21
  • 1
    Reference from geeksforgeeks https://www.geeksforgeeks.org/divide-large-number-represented-string/ – Rinshan Kolayil Aug 07 '21 at 18:22
  • Does this answer your question? [Working with large numbers in PHP](https://stackoverflow.com/questions/211345/working-with-large-numbers-in-php) – Don't Panic Aug 08 '21 at 09:00
  • None of them worked, i cant use any Lib. It seems that the Sandbox im Coding in doesnt Support these. – Carlos Kopra Aug 09 '21 at 06:53

1 Answers1

0

BC Math can calculate with strings. I am guessing you want to have the remainer of the division only? Then bcmod would be your choice. Otherwise pick bcdiv.

Note: works only php 7.2+, before this functions cuts with int precision as well.

Lu_kors
  • 80
  • 6
  • If I am guessing right and you want to validate IBANs have a look here https://stackoverflow.com/questions/20983339/validate-iban-php – Lu_kors Aug 08 '21 at 05:15
  • I cant use bc functions, cause their not defined in my Sandbox... It sas Error: Call to undefined function bcmod() I dont know why anybody would block that, but i cant use it. (i used it inside and outsite current namespace) – Carlos Kopra Aug 09 '21 at 06:54
  • This one helped, since here u can find an alternative to the written functions in PHP: stackoverflow.com/questions/20983339/validate-iban-php Thanks alot! – Carlos Kopra Aug 09 '21 at 07:02
  • Feel free to accept the answer if it helped. – Lu_kors Aug 10 '21 at 08:29