Jump to content


number rounding


6 replies to this topic

#1 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 10 November 2005 - 02:35 AM

I am making a script that will determine the page number of the thumbnail on the gallery view of the image that someone is currently viewing.

So far I have gotten this:
<?php 
//gallery page

	//number of images per gallery page
	$galimg = 28;

$galpg = $num / $galimg;
$galpg = number_format ($galpg, 0, '', '');
?>
http://www.monkeysinabarrel.com/ninja/gall...image.php?num=1

Now, my problem is that the number is rounded off. Up to image number 13 $galpg stays at 0, but from 14 to 28 I get 1. But I need the number result to stay the same all through 1 to 28.

Anyone know how I can fix this?

#2 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 10 November 2005 - 04:36 PM

For number rounding to the nearest whole number such as for pages, I use the php function called ceil

Read more about it here: http://www.php.net/ceil

For instance, if the number is 4.1, It would round to the next number which would be 5. This works perfect for pages because you can't have 4.1 pages, you have to have 5 pages for the extra info on that page to appear.

I hope that helps.

#3 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 10 November 2005 - 04:49 PM

From what it looks like, thats exactly what I'm looking for.
I'll try it out later and keep you updated if it worked.

Thanks.

#4 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 10 November 2005 - 04:50 PM

Simple explanation of ceil(): Round to Ceiling or Next Whole Number
Simple explanation of floor(): Round to Floor or Previous Whole Number

#5 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 10 November 2005 - 07:10 PM

and what if i want to round 4,5 or more to 5 and less than 4,5 to 4 for example?

#6 FabianN

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 10 November 2005 - 09:03 PM

Avalanche, on Nov 11 2005, 12:10 AM, said:

and what if i want to round 4,5 or more to 5 and less than 4,5 to 4 for example?
Well, that would be done with the number_format line, which is what I was originaly using.


And yes, I got it working the way I want. Thanks alot. :P

#7 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 11 November 2005 - 11:09 AM

nvm i found it already
round() will round the number to the nearest non decimal number





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users