colabus Posted June 26, 2006 Share Posted June 26, 2006 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:0400000000000000000204000000000000000003However I'm getting:0000000000000004E+180000000000000004E+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 https://forums.phpfreaks.com/topic/12928-php-number-handling-scientific-notation/ Share on other sites More sharing options...
colabus Posted June 26, 2006 Author Share Posted June 26, 2006 haha it would seem I was doing too much to get it working.[code]function increment($var) { $var2 = '_'.$var; return substr(++$var2,1);}[/code]php.net/manual/en/language.operators.increment.php#62479Cheers :) Link to comment https://forums.phpfreaks.com/topic/12928-php-number-handling-scientific-notation/#findComment-49624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.