Jump to content

PHP Number Handling - Scientific Notation


colabus

Recommended Posts

Hi all, have come across a small issue with some code I'm writing. Basically my users will enter in a serial number (alphanumeric) and then specify a quantity to add. My code then takes this and increments from the original.

I've had to consider a number of possible issues.

Using the ++ operator the serial will increase, however if the number is quite large it then if converted to scientific notation.

To give you an idea I type in: 04000000000000000001 (quantity of 3), so I'd expect to get:

04000000000000000002
04000000000000000003

However I'm getting:

0000000000000004E+18
0000000000000004E+18

[code]            if ($increment == 1)
            {
                $serialCutEnd = preg_replace('/[0-9]*$/', '', $serial);
                $serialEnding = substr($serial, strlen($serialCutEnd));
[/code]

This handles quite well but when the number gets big I run into trouble. Is there a way to force the value to remain a string? I've tried type casting but it seems as soon as I use the ++ operator issues arise.

I'd appreciate any guidance on this.

Cheers
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.