Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Simple math in php

Posted on 2011-10-30
2
Medium Priority
?
247 Views
Last Modified: 2013-12-12
Why does it echo 0.04 and 0.0333333333333 and not 25 and 30?
How do I fix? Thanks.

<?php
error_reporting(E_ALL);

$width = '50';
$height = '20';

$newWidth = 2/(100 - $width);
$newHeight = 2/(80 - $height);

echo $newWidth;
echo $newHeight;

?>

Open in new window

0
Comment
Question by:kadin
2 Comments
 
LVL 17

Accepted Solution

by:
psimation earned 2000 total points
ID: 37055124
Not exactly sure I understand what your script should do, but looking at what you *expect* to see, vs what you get, maybe you are just divinding before subtracting? Try this?

<?php
error_reporting(E_ALL);

$width = '50';
$height = '20';

$newWidth = (100 - $width)/2;
$newHeight =(80 - $height)/2;

echo $newWidth;
echo $newHeight;

?>
0
 

Author Closing Comment

by:kadin
ID: 37055131
Thank you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.
Suggested Courses

564 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