1.11M Members

how not to display zero in math

 
0
 

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.

 
0
 
$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.

 
0
 

thank you but I am getting two zeros - 00

 
0
 

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.

 
0
 

Basic maths:

if($ans > 0)echo $ans;
 
0
 

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

 
0
 

Show your code. Works for me.

 
0
 

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.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: