getting the last three characters

I want to query to a table to get the salary of an employee then match this salary figure to another table called categories, if found i should take for example let's say the a employees salary is $5000 and after searching through the categories table and found a matching value and the corresponding category to this value is managing director 8.9. What i need to do is pick the value corresponding to managing director 8.0 which is the basic entry for managing directors.
I can get the employe salary and also i am getting the category but getting the value of the basic entry is the problem. The basic entry is always X.0 where X is a variable. Can someone help me on this please?
Who is Participating?
edwardqConnect With a Mentor Commented:
If I understand right.

  You need the last 3 charaters in the Catagory.

I would query for the catagory and assign is to a string, Then I would use substr to get the last 3 char of the catagory..
$Catagory = Your SQL statement returning the catagory column.
$lastthree = substr($Catagory,strlen($Catagory) -3)
Steve BinkCommented:
If you type it as an integer, the decimal portion will be dropped.
AtourayAuthor Commented:
Ok i am getting the three digits right. But now after getting the digits that is after getting 8.6 and cast type it to 8.0, i am to concatenate it from the original string i got it from, for example "managing director 8.0" Any idea how can do this.?? I have different categories not only managing director.
Steve BinkConnect With a Mentor Commented:
Building on edwardq's example:

// $category is the SQL return
$lastthree = substr($category, strlen($category)-3);  // 8.6
$originalname = substr($category, 0, -3);  // "Managing Director "
$intlastthree = floor($lastthree);  // 8
$newname = $originalname . sprintf("%.1f",$intlastthree); // "Managing Director 8.0"

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.