Calculate quantity by the whole number

Asked

Viewed 47 times

1

I have to enter a record in the database according to an integer number. For example, 20, 21, 22, 23...29 I take the first number (in case 2) and enter 2 records. If it is 10, 11, 12, 13...19 (in case 1) I enter 1 record. 0,1,2,3,4...9 I enter none...

I just need to know if it is 0 to 9, 10 to 11, 20 to 22 and so on. According to which number I get the first number. The problem of doing for example with substr is if the number is 100 then it "will think" that is values between 10 and 19.

1 answer

5


Divide by 10, take the whole part, and use the result in your checks. For example:

$dezenas = floor($num / 10);
if ($dezenas == 1) {

} else if ($dezenas == 2) {

} // etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.