Solved

Obtaining Total Debt Service Ratio bit of a glitch

Posted on 2012-03-28
1
233 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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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 is …
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now