Solved

Obtaining Total Debt Service Ratio bit of a glitch

Posted on 2012-03-28
1
239 Views
Last Modified: 2012-08-14
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";
}

Open in new window

0
Comment
Question by:tjyoung
1 Comment
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37779241
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!";

Open in new window

HTH, ~Ray
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question