Jump to content

[SOLVED] unfort gonna have to reopen this. get first to numbers but keep as INT


polardude1983

Recommended Posts

I have a current_weight field. where ppl have their weight put in there so. if someone enters their weight in the form as 228 then the new_weight field says 22

 

This works if i keep it as new_weight CHAR(2), but then the 22 is a character and cannot be added to anything else since it is not an integer

 

so how can i do it so where new_weight is an integer but only grabs the first 2 numbers from 228?

 

new_weight INT(2) does not work it still grabs all 3

 

any idea on how to do this? im very puzzled

Link to comment
Share on other sites

well I'm wanting to keep the original 228 number as it is used later. but i want to extract the first 2 numbers from that 3 digit number and still keep it as an integer.

 

if someone enters 128 ill use that number later, but when i extract the first 2 numbers i will get 12. and i will need to use that new number later too.

 

Link to comment
Share on other sites

weight / 10 will give you the first 2 digits.

 

 

 

Note though that if someone puts in a weight under 100, it will give you 1 digit.

 

 

 

Also, you may want to floor() the number since MySQL will throw a warning if you try to store a float in an integer field.

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.