I have a simple math problem.. But what I would like to do is not have zero display if it equals out to zero...

<? echo $_POST['x'] * $_POST['y']?>

If this equals anything below zero I do not want the number to display.

5 Years
Discussion Span
Last Post by xbat
$x = intval($_POST['x']); //or floatval etc or just force type: (int) etc.
$y = intval($_POST['y']);

$ans = $x * $y;
if($ans >= 0)echo $ans;

Should do it.


I mean one zero. I still get one zero showing up.. Sorry I know whats going on. What I ment is after it does the math. Some equal out to zero. The ones that equal out to zero I do not want to display. the other ones that equal above in the final math problem I do want to display.

example 0X0= Nothing shown
1X1= 2 - this will display
2X0 = 0 - nothing will be shown.

Edited by xbat


Basic maths:

if($ans > 0)echo $ans;

i still get a zero showing up with if($ans > 0)echo $ans;


Show your code. Works for me.

Edited by diafol


I think i found out whats going on.. I have php page with javascript, when I reference the post.. Its pulling fromthe javascript which does part of the math then it gives me 0.. What i'm doing is bassically echoing the page in javascript which gives me the zero.. I will try to post more code later.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.