p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: number_format problem?


Message #1 by "RIchard Feaver" <rfeaver@r...> on Wed, 10 Jan 2001 16:56:36 -0000
hello all



Can anyone tell me how i can use number format to round to 2.decimal

poiints.

problem is i know its number_format($whatever,2);

but when the figures go into the 1000`s a comma appears ie. 1,600.00 and i

need to be able to display the number without commas. if i dont use number

format i get the number to the equiverlant of 4 decimal places.



if anyone could help that would be a real bonus



cheers



rich



Message #2 by <gaurav?khanna25@y...> on Wed, 24 Jan 2001 14:40:27 +0530
hi richard,



well u can use the " sprintf() " function:

the syntax is



string sprintf(string format, mixed [args]... );



for eg : -



$anynumber =   1234567890.1234567890 ;  // for the sake of eg & yaa it's

more than 1000's





echo "<br> Original  Number is  = $anynumber <br> " ;



// since u wanted it should show with 2 decimals ..... " 0.2f " is used in

sprintf .. u can change it accrdgly





$gaurav = sprintf("%0.2f",$anynumber);  // $gaurav now holds the value but

with 2 decimals



echo "<br> Converted Number Now Becomes  = $gaurav <br> " ;



//  output is  1234567890.12

Regards Gaurav Khanna



mailme if any problem bye



gaurav_khanna25@y...





-----Original Message-----

From: RIchard Feaver <rfeaver@r...>

To: beginning php <beginning_php@p...>

Date: Wednesday, January 10, 2001 10:36 PM

Subject: [beginning_php] number_format problem?





>hello all

>

>Can anyone tell me how i can use number format to round to 2.decimal

>poiints.

>problem is i know its number_format($whatever,2);

>but when the figures go into the 1000`s a comma appears ie. 1,600.00 and i

>need to be able to display the number without commas. if i dont use number

>format i get the number to the equiverlant of 4 decimal places.

>

>if anyone could help that would be a real bonus

>

>cheers

>

>rich

>

>

  Return to Index