Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2004, 11:47 PM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default number of decimal?

For example, i have a calculation in the php page where 10/3=3.333333
How can i make the 3.33333 to be displayed as 3.33 (two decimal)?

 
Old February 11th, 2004, 02:25 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:From: http://www.php.net/round

float round ( float val [, int precision])

Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).

Example 1. round() examples

<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.04
echo round(5.055, 2); // 5.06
?>
hth,
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression for number upto 2 decimal place swati_joshi ASP.NET 1.0 and 1.1 Basics 3 July 31st, 2008 11:23 AM
Number with 2 decimal places only pallone SQL Server 2000 4 July 3rd, 2007 07:29 AM
function to create whole number from decimal dhx10000 Classic ASP Professional 1 July 18th, 2006 08:17 PM
round up a decimal number semooth VB How-To 3 October 4th, 2005 02:33 PM
How to check if a number has a decimal snowy0 VB How-To 5 August 5th, 2004 02:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.