Currency conversion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Currency conversion

Post 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
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Re: Currency conversion

Post by N1gel »

There are these two functions in the PHP manual. They might help

money_format

number_format
Post Reply