Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,910 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,738 people online right now. Registration is fast and FREE... Join Now!




set precision

 
Reply to this topicStart new topic

set precision

imaro
16 Mar, 2008 - 08:36 AM
Post #1

New D.I.C Head
*

Joined: 16 Feb, 2008
Posts: 10


My Contributions
how to set precision in PHP....
as the example...the number 2.3...it will display as 2.30...
can anyone help me...
User is offlineProfile CardPM
+Quote Post

MitkOK
RE: Set Precision
16 Mar, 2008 - 09:12 AM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 314



Thanked: 12 times
Dream Kudos: 250
My Contributions
php
$precision = 2;

ini_set("precision", $precision);

User is offlineProfile CardPM
+Quote Post

imaro
RE: Set Precision
16 Mar, 2008 - 11:12 AM
Post #3

New D.I.C Head
*

Joined: 16 Feb, 2008
Posts: 10


My Contributions
QUOTE(MitkOK @ 16 Mar, 2008 - 10:12 AM) *

php
$precision = 2;

ini_set("precision", $precision);





owh...thanks...
i found another way...
number_format(2.5,2);
the value will be 2.50....
anyway...thanks
User is offlineProfile CardPM
+Quote Post

spearfish
RE: Set Precision
16 Mar, 2008 - 12:18 PM
Post #4

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
Formatted strings would be the way to do it.
User is offlineProfile CardPM
+Quote Post

_net
RE: Set Precision
17 Mar, 2008 - 03:55 PM
Post #5

D.I.C Head
**

Joined: 22 Sep, 2007
Posts: 146


My Contributions
As speafish said:

printf("number is %.2f",2.5);

smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 09:56PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month