1,105,556 Community Members

how not to display zero in math

xbat
Junior Poster in Training
83 posts since Jun 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Banned
 
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.

Member Avatar
diafol
Where are my eyes?
12,986 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,849 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
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.

xbat
Junior Poster in Training
83 posts since Jun 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Banned
 
0
 

thank you but I am getting two zeros - 00

xbat
Junior Poster in Training
83 posts since Jun 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Banned
 
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.

Member Avatar
diafol
Where are my eyes?
12,986 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,849 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

Basic maths:

if($ans > 0)echo $ans;
xbat
Junior Poster in Training
83 posts since Jun 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Banned
 
0
 

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

Member Avatar
diafol
Where are my eyes?
12,986 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,849 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

Show your code. Works for me.

xbat
Junior Poster in Training
83 posts since Jun 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Banned
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: