Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

Cannot output integer in PHP!!

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

Cannot output integer in PHP!!

Postby beechgrove » Sat Sep 08, 2012 1:20 pm

Hi

I am still pretty new to PHP and have written a calculator script that takes Number1, divides it by 100, multiplies it by Number 2 then finally divides it by 20 (trust me there is a purpose to this!!)

The problem is that it (for instance) when Number1 is 254 and Number2 is 480 it returns 60.9600 when what I actually want it to return is 61.

I have tried every round(), floor() etc statement I can find but it still returns 60.9600!!!

The calculation is: $answare = $number1/100*$number2/20;

Please, please can someone tell me how to return just the integer part?

Thanks
beechgrove
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Sep 08, 2012 1:12 pm

Re: Cannot output integer in PHP!!

Postby egami » Tue Sep 11, 2012 6:47 am

$answer = round (($number1 / 100) * ($number2 / 20),0);
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to Your Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron