Connecting Tech Pros Worldwide Help | Site Map

Format float

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 14th, 2006, 12:55 PM
WJ Zeeuwen
Guest
 
Posts: n/a
Default Format float

Hi all,

Is it possible to adjust the number of digits in a float?

For example $test = 1/3; echo ($test); gives 0.33333333.. But i only
want 0.33
Is there a function or do i have to use round($test*100)/100

Thanx,
WJ

  #2  
Old May 14th, 2006, 01:15 PM
Rik
Guest
 
Posts: n/a
Default Re: Format float

WJ Zeeuwen wrote:[color=blue]
> Hi all,
>
> Is it possible to adjust the number of digits in a float?
>
> For example $test = 1/3; echo ($test); gives 0.33333333.. But i only
> want 0.33
> Is there a function or do i have to use round($test*100)/100[/color]

I'd use round($test,2);
Also possible is number_format();

Grtz,
--
Rik Wasmus


  #3  
Old May 14th, 2006, 08:05 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: Format float

WJ Zeeuwen wrote:[color=blue]
> Hi all,
>
> Is it possible to adjust the number of digits in a float?
>
> For example $test = 1/3; echo ($test); gives 0.33333333.. But i only
> want 0.33
> Is there a function or do i have to use round($test*100)/100
>
> Thanx,
> WJ[/color]

If all you want to do is display the value 0.33 without actually changing the
number (which will affect future math operations), you can use

printf("%01.2f", 0.33);

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.