Forum Moderators: coopster

Message Too Old, No Replies

2 Decimal Places

         

almo136

8:20 pm on Jul 8, 2010 (gmt 0)

10+ Year Member



I have this piece of code:

<?php echo ((($totalItemQty - 1) * 2.00) + 3.50) ?>


Which prints a number ie. 10.5

How can I make it so that there will always be 2 decimal places ie. 10.50.

The outputted number is being used as a currency.

Thanks!

Readie

8:54 pm on Jul 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[php.net...]

<?php echo number_format(((($totalItemQty - 1) * 2) + 3.5), 2); ?>


:)

almo136

9:05 pm on Jul 8, 2010 (gmt 0)

10+ Year Member



thanks!

rocknbil

2:05 am on Jul 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



or sprintf() . . . :-)

Matthew1980

5:26 am on Jul 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

>>or sprintf() . . . :-)

I was going to suggest that, but for the life of me I cannot remember the formatting specifier, even though: [uk3.php.net ] that explains it :)

Doh!

Cheers,
MRb