Solved

Obtaining Total Debt Service Ratio bit of a glitch

Posted on 2012-03-28
1
236 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 109

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.htaccess 5 39
PHP AJAX JSON 2 61
google analytics on wp-admin password protected area 2 24
How is this connection happening? 3 15
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

803 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