Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Obtaining Total Debt Service Ratio bit of a glitch

Posted on 2012-03-28
1
Medium Priority
?
243 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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 count occurrences of each item in an array.

722 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