Page 1 of 1

Currency conversion

Posted: Wed May 28, 2008 2:55 am
by Addos
Hi,
I’m running a small currency test and can’t seem to get a satisfactory output in that either the results is short a numeric value at the end or has an unnecessary one at the beginning.

For example this returns a Euro value of 25.4 and I want to see 25.40

Code: Select all

<?php
$dollar = 40.00 ;
$euro = 0.63 ;
$total = ($dollar * $euro);
 
echo $total ;// 25.4 
?>
This returns 0.945 and I just want .94 (cent) or 00.94

Code: Select all

<?php
$dollar = 1.50 ;
$euro = 0.63 ;
$total = ($dollar * $euro);
 
echo $total ;// 0.945
?>
Is there any specific formula that I can use to get a balanced display or is it more complex that I first imagined?
Thanks

Re: Currency conversion

Posted: Wed May 28, 2008 3:33 am
by N1gel
There are these two functions in the PHP manual. They might help

money_format

number_format