We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,376 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

how not to display zero in math

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.

2
Contributors
7
Replies
8 Hours
Discussion Span
6 Months Ago
Last Updated
8
Views
xbat
Junior Poster in Training
Banned
83 posts since Jun 2012
Reputation Points: -4
Solved Threads: 0
Skill Endorsements: 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.

diafol
Keep Smiling
Moderator
10,668 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57

thank you but I am getting two zeros - 00

xbat
Junior Poster in Training
Banned
83 posts since Jun 2012
Reputation Points: -4
Solved Threads: 0
Skill Endorsements: 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.

xbat
Junior Poster in Training
Banned
83 posts since Jun 2012
Reputation Points: -4
Solved Threads: 0
Skill Endorsements: 0

Basic maths:

if($ans > 0)echo $ans;
diafol
Keep Smiling
Moderator
10,668 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57

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

xbat
Junior Poster in Training
Banned
83 posts since Jun 2012
Reputation Points: -4
Solved Threads: 0
Skill Endorsements: 0

Show your code. Works for me.

diafol
Keep Smiling
Moderator
10,668 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57

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.

xbat
Junior Poster in Training
Banned
83 posts since Jun 2012
Reputation Points: -4
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0756 seconds using 2.68MB