Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:37:19+00:00 2026-05-26T15:37:19+00:00

Conclusion: Marc B’s solution is a 64 Bit, but for 32 Bit I’m not

  • 0

Conclusion: Marc B’s solution is a 64 Bit, but for 32 Bit I’m not sure you can get the accuracy needed

UPDATE #1: 19 character length is the string/number max length

UPDATE #2: This kinda works but only if the number is in string format like this:

$number = "12345678901234567890";

if I pass it like this

$number = 12345678901234567890;

I get an warning:

Warning: gmp_abs(): Unable to convert variable to GMP – wrong type

Updated Class

class StringToInteger {
    public static function getInteger($number) {
        //return sprintf('%.0f', $number);
    //$number = sprintf('%d', $number);
    $number = gmp_abs($number);
    return gmp_strval($number);
    }
}

ORIGINAL QUESTION BELOW:

I have some data being passed either as a string or integer (Think Phone Number but longer), most of the data is just a long number like this:

1234567890123456789

But sometimes it comes like this

123-456-789-012-345-678-9 // could be other non numeric characters as well

Using the below functions doesn’t give the desired results

class StringToInteger {
    public static function getInteger($number) {
        return number_format($number, 0, '.', '');
    }
}

class NumericOnly {
    public static function formatNumber($number) {
        return preg_replace("/[^\d]/", "", $number); 
    }
}

Pass as numeric:

$number = 1234567890123456789;
// output: 1.23456789012E+18 can't use this
echo "Number: {$number}\n"; 

// Where did my number go? truncated/rounded?
// output: 12345678901218 can't use this
echo "Numeric Only: ".NumericOnly::formatNumber($number)."\n"; 

// Where did my number go? truncated?
// output: 1234567890123456768 can't use this
echo "String To Integer: ".StringToInteger::getInteger($number)."\n"; 

Pass as string:

$string = '1234567890123456789';
// output: 1234567890123456789
echo "String Number: {$string}\n"; 

// Works
// output: 1234567890123456789
echo "String Numeric Only: ".NumericOnly::formatNumber($string)."\n"; 

// Where did my number go? truncated?
// output: 1234567890123456768 can't use this
echo "String To Integer: ".StringToInteger::getInteger($string)."\n"; 

// After Conversion, truncated?
// output: 1234567890123456768 can't use this
echo "After String To Integer: ";
echo StringToInteger::getInteger(NumericOnly::formatNumber($string))."\n"; 

Alpha Numeric

$string = '123-456-789-012-345-678-9';
// output: 123-456-789-012-345-678-9 can't use this
echo "String Number: {$string}\n"; 

// Works
// output: 1234567890123456789
echo "String Numeric Only: ".NumericOnly::formatNumber($string)."\n"; 


// After Conversion, truncated?
// output: 1234567890123456768 can't use this
echo "After String To Integer: ";
echo StringToInteger::getInteger(NumericOnly::formatNumber($string))."\n"; 

Any ideas on how to get a Long Integer (The full correct number)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:37:20+00:00Added an answer on May 26, 2026 at 3:37 pm

    The largest integer that can be represented in a 64bit PHP install, compared to your number:

       9,223,372,036,854,775,808 - largest possible signed 64bit integer
      12,345,678,901,234,567,890 - your number
    

    since you’re exceeding the maximum number size, you can’t expect to get useful results without using something like bcmath/GMP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying this a few different ways, but I'm reaching the conclusion that
I've been thinking about a program logic, but I cannot draw a conclusion to
I am rapidly coming to the conclusion that this is not feasible, although for
So I started to make comments module and came to conclusion that I'm not
Not that I have time to discuss this properly to reach a conclusion and
I thought hours about that problem but I didn't come to any conclusion. My
I struggled half a day and came to conclusion that it can't be done.
There were a number of other threads like this, but the usual conclusion was
I'm struggling to get my head around LINQ and have come to the conclusion
For some time I am battling to solve this problem but I am not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.