How to format a number after division to two decimal places?

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 478
  • Loc: Conroe, Texas
  • Status: Offline

Post May 25th, 2012, 1:13 pm

I am probably completely missing this but i am wanting this to take it to 2 decimal places not round the whole thing..

$size = ceil($d['size']/1024/1024);

so with out the ceil
I get this number
1.24835586548Mb

and with the ceil i get 2mb

i want it to look like this
1.25

i want it to go 2 decimal places
Thanks, Josh --DemonMaestro
www.LilNetwork.com
Fun Website www.ShoutsCloud.com
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 25th, 2012, 1:13 pm

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8922
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post May 25th, 2012, 1:35 pm

I am thinking you are using PHP. I would use the PHP round function:

http://php.net/manual/en/function.round.php

So you would do something like:

PHP Code: [ Select ]
$size = round($d['size']/1024/1024, 2);


The second argument is the precision that you want.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 478
  • Loc: Conroe, Texas
  • Status: Offline

Post May 25th, 2012, 1:44 pm

thanks that worked. i guess i didn't scroll down far enough and had seen the round feature..
Thanks, Josh --DemonMaestro
www.LilNetwork.com
Fun Website www.ShoutsCloud.com
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 478
  • Loc: Conroe, Texas
  • Status: Offline

Post May 25th, 2012, 1:59 pm

another question for some reason i keep getting

Warning: Cannot modify header information - headers already sent by (output started at /home/ppeeps/ekazer.com/pages/Files/index.php:4) in /home/ppeeps/ekazer.com/pages/Files/index.php on line 133


but that line is
header("Location: ".$session->referrer);

the $session->referrrer does work and dont have any issues. but it does it rather i use that or i use
header("Location: index.php");

any ideas?
Thanks, Josh --DemonMaestro
www.LilNetwork.com
Fun Website www.ShoutsCloud.com
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6128
  • Loc: Seattle, WA
  • Status: Offline

Post May 25th, 2012, 4:04 pm

You can only use header() before PHP produces ANY output to the client, e.g. echo() statements or the like.
The Beer Monocle. Classy.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Joined: Jun 21, 2006
  • Posts: 478
  • Loc: Conroe, Texas
  • Status: Offline

Post May 28th, 2012, 6:59 pm

spork wrote:
You can only use header() before PHP produces ANY output to the client, e.g. echo() statements or the like.


so what is recommended?
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6128
  • Loc: Seattle, WA
  • Status: Offline

Post May 29th, 2012, 11:07 am

Find wherever in your code that you're producing output before the call to header(), and remove it.
The Beer Monocle. Classy.

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 119 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.