PHP - Round Numbers
i have a price i want to add 10%-15% to the base price and that the result
will be rounded to 9 in the ones digit place. for example 85 +15%=97.7 $result=99 117+15%=134.55 $result = 139 played with round() and ceil() Similar TutorialsHi, I need to sort variables in groups of up to 15 and put it in an array. For example: $exstract['center_tabOpBody_0'] =5 $exstract['center_tabOpBody_1'] =6 $exstract['center_tabOpBody_2'] =8 $exstract['center_tabOpBody_3'] =1 Should yield: ARRAY( = center_tabOpBody_1,center_tabOpBody_2,center_tabOpBody_3 // <-----15 [1] = center_tabOpBody_0 //<----5 ) Is there some simple function do do the "efficiency" sort? Thanks, Vadim hi know who to round a number to the nearest whole number, if i use echo round(9.5); it echo's 10 and if i use echo round(9.2); it echo's 9 i want it so it always rounds up? can anyone help? cheers matt hello guys, im creating a search result page that uses pagination, and im trying to figure out how many total pages their are going to be in my links with the page numbers. this is probably something really simple, ive been writing scripts for the last few hours and have a bit of a headache, any help would be appreciated here's the coding and the results i want: <?php $per_page = 10; $rows = mysql_query("SELECT COUNT(*) FROM articles WHERE text LIKE $string"); // this will return 31 $pages = $rows / $per_page; // returns 3.1 $total_pages = round($pages); // returns 3, want to round 3.1 up to 4 here ?> I am trying to output only 40 of the latest files uploaded on the database server. But when I am trying to see the files uploaded on the server I am getting this error: Warning: round() expects parameter 2 to be long, string given in C:\wamp\www\mshare\lista.php on line 8 Call Stack The code: Code: [Select] <?php function bytestostring($size, $precision = 0) { $sizes = array('YB', 'ZB', 'EB', 'PB', 'TB', 'GB', 'MB', 'kB', 'B'); $total = count($sizes); while($total-- && $size > 1024) $size /= 1024; return round($size, $precision)." ".$sizes[$total]; } echo '<div class="header">40 last uploaded files:</div>'; $sql = "SELECT * FROM filer order by id desc limit 40"; $q = mysql_query($sql); echo '<table style="width: 100%;">'; while ($r = mysql_fetch_array($q)) { $i++; $id = $r['id']; $filnamn = $r['name']; $filtyp = explode("/", $r['type']); $filtyp = ucwords($filtyp[0]); if($filtyp == "") { $filtyp = "Unkown"; } $filstorlek = bytestostring($r['size'], ""); $a = $i%2; echo'<tr><td class="lista">'; echo ''.$i.'. <td class="lista">'.$filnamn.'<td class="lista">'.$filtyp.' <td class="lista">'.$filstorlek.' <td class="lista"><a href="download.php?id='.$id.'"'.$a.'"><img src="download-icon.jpg" class="imagedow"></a>'; } echo "</table>"; ?> I am new to PHP coding so you guys just know. This works echo $data3['value']; But this doesn't echo round($data3['value'], 2); Can someone please advise me as to what I am doing wrong? Code: [Select] $newrating = round($imageinfo['rating'],2); this outputs: 4.49 in my db rating is 4.4884 all i need is the 4.... would i use some type of preg_replace or something just to grab the first 1 before the decimal? (all i need is the first number before the decimal) I need to take a time and convert so it is rounded up or down to the nearest 0 or 5. Code: [Select] function roundMe ($time, $upDown) { if($upDown==1) { //round up } else { //round down } return $x; } echo roundMe("16:22", 1); // returns 16:25 echo roundMe("16:22", 0); // returns 16:20 echo roundMe("16:25", 1); // returns 16:25 echo roundMe("16:59", 1); // returns 17:00 echo roundMe("16:59", 0); // returns 16:55 HOw to get the AVERAGE of my entire database? $query = "SELECT ROUND(AVG(scores)) FROM table"; Thanks! Bickey Hi.. I encountered problem in rounding of numbers into two decimal places. here is my sample code: if($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) { $TAX = ($TotEarn - 7917); $TAX = (937.50 + ($TAX * .25)); $TAX = number_format($TAX, 2, '.', ''); } for example from this: $TAX = ($TotEarn - 7917); $TAX = (937.50 + ($TAX * .25)); the output is: 1417.615 using this: $TAX = number_format($TAX, 2, '.', ''); the output was : 1417.61 but it should be : 1417.62 Thank you Hey guys, I use the code below to add a corners to an image and it works great but when i add a border to the image it add a square.... any ideas how i can add a border to the rounded image? <?php $image_file = $_GET['src']; $corner_radius = isset($_GET['radius']) ? $_GET['radius'] : 20; // The default corner radius is set to 20px $topleft = (isset($_GET['topleft']) and $_GET['topleft'] == "no") ? false : true; // Top-left rounded corner is shown by default $bottomleft = (isset($_GET['bottomleft']) and $_GET['bottomleft'] == "no") ? false : true; // Bottom-left rounded corner is shown by default $bottomright = (isset($_GET['bottomright']) and $_GET['bottomright'] == "no") ? false : true; // Bottom-right rounded corner is shown by default $topright = (isset($_GET['topright']) and $_GET['topright'] == "no") ? false : true; // Top-right rounded corner is shown by default $imagetype=strtolower($_GET['imagetype']); $backcolor=$_GET['backcolor']; $endsize=$corner_radius; $startsize=$endsize*3-1; $arcsize=$startsize*2+1; if (($imagetype=='jpeg') or ($imagetype=='jpg')) { $image = imagecreatefromjpeg($image_file); } else { if (($imagetype=='GIF') or ($imagetype=='gif')) { $image = imagecreatefromgif($image_file); } else { $image = imagecreatefrompng($image_file); } } $size = getimagesize($image_file); // Top-left corner $background = imagecreatetruecolor($size[0],$size[1]); imagecopymerge($background, $image, 0, 0, 0, 0, $size[0], $size[1], 100); $startx=$size[0]*2-1; $starty=$size[1]*2-1; $im_temp = imagecreatetruecolor($startx,$starty); imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $size[0], $size[1]); $bg = imagecolorallocate($im_temp, hexdec(substr($backcolor,0,2)),hexdec(substr($backcolor,2,2)),hexdec(substr($backcolor,4,2))); $fg = imagecolorallocate($im_temp, hexdec(substr($forecolor,0,2)),hexdec(substr($forecolor,2,2)),hexdec(substr($forecolor,4,2))); if ($topleft == true) { imagearc($im_temp, $startsize, $startsize, $arcsize, $arcsize, 180,270,$bg); imagefilltoborder($im_temp,0,0,$bg,$bg); } // Bottom-left corner if ($bottomleft == true) { imagearc($im_temp, $startsize, $starty-$startsize,$arcsize, $arcsize, 90,180,$bg); imagefilltoborder($im_temp,0,$starty,$bg,$bg); } // Bottom-right corner if ($bottomright == true) { imagearc($im_temp, $startx-$startsize, $starty-$startsize,$arcsize, $arcsize, 0,90,$bg); imagefilltoborder($im_temp,$startx,$starty,$bg,$bg); } // Top-right corner if ($topright == true) { imagearc($im_temp, $startx-$startsize, $startsize,$arcsize, $arcsize, 270,360,$bg); imagefilltoborder($im_temp,$startx,0,$bg,$bg); } $newimage = imagecreatetruecolor($size[0],$size[1]); imagecopyresampled($image, $im_temp, 0, 0, 0, 0, $size[0],$size[1],$startx, $starty); // Output final image header("Content-type: image/png"); imagepng($image); imagedestroy($image); imagedestroy($background); imagedestroy($im_temp); ?> hello, if i have the following, how would i display it? Code: [Select] function minutes_round ($hour = "$signintime", $minutes = '5', $format = "H:i") { $seconds = strtotime($hour); $rounded = round($seconds / ($minutes * 60)) * ($minutes * 60); return date($format, $rounded); } Hi there. I am trying to display numbers if they have the numbers like: number_format($price,2) This gives us two decimal places i.e 7.23 Now thats fine, I would like to round the last two decimal places. I would like to make it 7.25, (rounding it from 7.23 to 7.25) Similarly making: 12.44 to 12.45 33.18 to 33.20 52.13 to 52.15 So actually rounding the last two places. Coz obviously customers won't be able to pay 52 dollars 13 cents. So therefore rounding the last cent's (decimal part) making it to 52.15 Thank you. All comments and feedback are welcomed. (d can you have something like.. echo $whatever; this putput 1.2 can you split this number so the first integer will be in $val"(1)" or whatever and the second integer after the "." will be in $val2"(2)" hello again how to get ratio with result max 3 numbers such as 3.00 or 0.11 if im do $mynumbers = 1000 / 400; so reusult to be 1.00 ? and how to put full stop if it is more then 4 numbers result instead of 1000 to have 1.000 Working through some beginner stuff and ive copied some code straight out the textbook, word for word yet it produces: Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in C:\wamp\www\PHP Work\StringtoNumbers.php on line 11 <html> <head> <title>Strings Into Numbers</title> </head> <body> <h1>Strings Into Numbers</h1> <ul> <?php $n = "0x237a"; echo "<li>".$n."</li>" echo "<li>".($n * 3)."</li>"; $n2 = "34re5"; echo "<li>".($n2 + 2)."</li>"; $n3 = "boo"; echo "<li>".($n3 + 2)."</li>"; ?> </ul> </body> </html> Hi i got an error. I cant get $new_score and $new_played variables. $name = $_POST["name"]; $score = $_POST["score"]; $result = mysql_query("SELECT * FROM taure_lentele WHERE name='$name'"); $row = mysql_fetch_array($result); if(mysql_num_rows(mysql_query("SELECT name FROM taure_lentele WHERE name='$name'") ) == 1 ) { $old_score = $row['score']; $score + $old_score = $new_score; $old_played = $row['played']; $new_played = $old_played++; mysql_query("DELETE FROM taure_lentele WHERE name='$name'"); mysql_query("insert into `taure_lentele` set `name` = '$name', `score` = '$new_score', `played` = '$new_played"); } is this a proper way of entering this? Code: [Select] $result = mysql_query("SELECT * FROM jobs WHERE id2 >= '$startdate' AND id2 < '$enddate' ORDER BY id"); Hey I have a quick question. I am trying to have a part of this PHP script compare two numbers. There is a randomly generated two-digit number named $random and There is another two digit number named $number. I want to make it so the PHP checks to see if $number has any of the same charcters as $random. I don't know how to do this though. I suspect that somehow both numbers need to be broken apart somehow. Any advice would be appreciated. Let me know if I should explain it more clearly Thanks a ton! Hey i'm just woundering how i would echo numbers from a database like 1000000 lets say 1 million how would i go about on echoing it like this 1,000,000 ZhsHero Hello Guys, I have a var for height like $height="67" and want to be able to split that number into, so that I can display 6 feet 7 inches but I have not figured out how to do it.. Please advise.. This is the current code I am working with but doesn't work. The problem is that explode won't work without some type of separator. Code: [Select] $height2 = explode(" ", $height); echo "This is feet". $height2[0] ."<br>"; echo "This is inches". $height2[1]. "<br>"; |