Solved

Obtaining Total Debt Service Ratio bit of a glitch

Posted on 2012-03-28
1
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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.

624 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