# Obtaining Total Debt Service Ratio bit of a glitch

Hello,
I have an online app that as part of it being used determines your total debt service ratio simply by dividing expenses / income

Found if people were to put in crazy number like:
I earn \$2000 and have expenses that are \$5000 it returns 2.5 in this case.
Given my code below, it strips off the 2 and returns with a 50% debt service ratio.

Any idea how it should look so it will return a proper fraction when the numbers are sensible, but return differently if you are way over on your expenses?

I suppose I could test if the expenses are greater then the income but wondered if there was a better way of doing it.

Hope that makes some sense.
``````\$tdsr = \$expenses / \$income;

\$tdsr = round(\$tdsr,2);
\$new_tdsr = explode(".", \$tdsr);
\$tdsr = \$new_tdsr[1];

if (strlen(\$tdsr) == 1) {
\$tdsr = \$tdsr."0";
}
``````
LVL 1
Asked:
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
See http://www.laprbass.com/RAY_temp_tjyoung.php
Outputs: WITH EXPENSES = 5000 AND INCOME = 2000 YOUR TOTAL DEBT SERVICE RATIO IS 250% AND THIS IS TOO HIGH!
``````<?Php // RAY_temp_tjyoung.php
error_reporting(E_ALL);

// TEST DATA
\$expenses = 5000;
\$income   = 2000;

// COMPUTE THE RATIO AS A PERCENTAGE VALUE
\$tdsr = (\$expenses / \$income) * 100.0;

// PREPARE A PRINTABLE VERSION (COULD DO THIS WITH OTHER NUMBERS, TOO)
\$tdsr_printable = number_format(\$tdsr) . '%';

// SHOW THE WORK PRODUCT
echo "WITH EXPENSES = \$expenses AND INCOME = \$income YOUR TOTAL DEBT SERVICE RATIO IS \$tdsr_printable ";
if (\$tdsr > 50.0) echo "AND THIS IS TOO HIGH!";
``````
HTH, ~Ray

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.