Convert numbers question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Convert numbers question (/showthread.php?tid=69613) |
Convert numbers question - wolfgang1983 - 12-23-2017 Hi, I want to be able to convert my KB numbers. For example the out put I am after lets say if my string is 471858 KB/MB then I would like it to change be able to echo to 0.04 GB I can't seem to get it to work for round($count, 1) What would be best way. I have tried some kb to gb converter script like but does not convert it to like 0.04GB PHP Code: function byte_convert($size) { PHP Code: $quota = imap_get_quotaroot($mbox, "INBOX"); RE: Convert numbers question - Kel_Novi - 12-23-2017 First convert 471858 to decimal , so that would be 0.471858 then divide it by 1024 and then you will get the result of 0.04 RE: Convert numbers question - Wouter60 - 12-23-2017 Maybe this will help: PHP Code: function byte_convert($size,$unit='MB',$decimals=2) { Call the function like this: PHP Code: echo byte_convert(150000000,'TB',4); RE: Convert numbers question - wolfgang1983 - 12-23-2017 (12-23-2017, 06:27 AM)Wouter60 Wrote: Maybe this will help: I tried this $this->format_size($count, 'GB') PHP Code: function format_size($size, $unit = 'MB', $decimals = 2) { My all the total of my email sizes are 471858 But only returns 0.00 GB not 0.04 GB RE: Convert numbers question - PaulD - 12-23-2017 471858 bytes is 0.0004 GB. So the function is returning the correct figure to 2 decimal places. RE: Convert numbers question - wolfgang1983 - 12-23-2017 (12-23-2017, 03:54 PM)PaulD Wrote: 471858 bytes is 0.0004 GB. So the function is returning the correct figure to 2 decimal places. OK so will have to change a couple of things cool bit more practice for me |