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.
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.
$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.
thank you but I am getting two zeros - 00
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.
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.
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.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.