MasterACE14 Posted February 16, 2008 Share Posted February 16, 2008 Hey, Is it possible to make a varchar field, and use it as if it was a Int field? and if so, how big can the varchar field be? What sought of number size can it accomodate? Regards ACE Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 16, 2008 Share Posted February 16, 2008 Why would you want to use a VARCHAR datatype to store integers? VARCHAR is used to store small strings - maximum length would be 255 characters. Use INT datatype to store integers. Quote Link to comment Share on other sites More sharing options...
richardw Posted February 16, 2008 Share Posted February 16, 2008 As far as storing numbers, yes. Make sure to set the field size to hold the largest of your expected number. When actually processing, use intval() <?php $n1= "100"; // assume it came from a vchar field $n2 = "25"; $n3 = intval($n1)+ intval($n2); echo $n3; ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted February 16, 2008 Share Posted February 16, 2008 The max unsigned integer size is about 4,000,000,000 (10 digits). To store as varchar is 11 bytes. To store as int is 4 bytes. So why bother with varchar for integers? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted February 16, 2008 Author Share Posted February 16, 2008 The max unsigned integer size is about 4,000,000,000 (10 digits). To store as varchar is 11 bytes. To store as int is 4 bytes. So why bother with varchar for integers? ok, I think i'll stick with integers. Thanks guys. ACE Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.