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

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 677
  • Loc: Conroe, Texas

Post 3+ Months Ago

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
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

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.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 677
  • Loc: Conroe, Texas

Post 3+ Months Ago

thanks that worked. i guess i didn't scroll down far enough and had seen the round feature..
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 677
  • Loc: Conroe, Texas

Post 3+ Months Ago

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?
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

You can only use header() before PHP produces ANY output to the client, e.g. echo() statements or the like.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 677
  • Loc: Conroe, Texas

Post 3+ Months Ago

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
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

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

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: VanessaGilbert and 140 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.