Connecting Tech Pros Worldwide Help | Site Map

Format float

  #1  
Old May 14th, 2006, 01:55 PM
WJ Zeeuwen
Guest
 
Posts: n/a
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, 02:15 PM
Rik
Guest
 
Posts: n/a

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, 09:05 PM
Jerry Stuckle
Guest
 
Posts: n/a

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
==================
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question for a REAL expert on casting double to float... Bill Reid answers 22 July 15th, 2008 09:45 AM
Format float fmt answers 7 February 5th, 2006 10:55 PM
Help need with converting Hex string to IEEE format float i_vincent@hotmail.com answers 7 July 18th, 2005 07:58 PM