php-windows Digest 4 Dec 2004 08:59:21 -0000 Issue 2495

Topics (messages 25113 through 25117):

Re: displaying neat and tidy currency notation?
        25113 by: N.A.Morgan.bton.ac.uk
        25114 by: Wagner, Aaron
        25115 by: William Cox
        25116 by: re_action
        25117 by: George Pitcher

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
You could try concatenating a string of "0"s (�25.5000) on the end and using
substr on the whole to get your �25.50.

$currency = $currency . "000";
$currency = substr( $currency, 0, strpos($currency,'.') + 3 )

Neil Morgan

-----Original Message-----
From: George Pitcher [mailto:[EMAIL PROTECTED] 
Sent: 03 December 2004 15:49
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] displaying neat and tidy currency notation?

Hi,

I want to be able to display the results of some calculations as currency
such as �25.50, but round($var,2) produces �25.5.

I've tried writing my own function but that just fouled up the calculation.

Any tips or suggestions?

Cheers

George in Oxford

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
http://us2.php.net/manual/en/function.number-format.php

use number_format function.

string number_format ( float number [, int decimals] ) string number_format ( 
float number, int decimals, string dec_point, string thousands_sep )

> -----Original Message-----
> From: George Pitcher [mailto:[EMAIL PROTECTED]
> Sent: December 03, 2004 10:49
> To: [EMAIL PROTECTED]
> Subject: [PHP-WIN] displaying neat and tidy currency notation?
> 
> 
> Hi,
> 
> I want to be able to display the results of some calculations 
> as currency
> such as �25.50, but round($var,2) produces �25.5.
> 
> I've tried writing my own function but that just fouled up 
> the calculation.
> 
> Any tips or suggestions?
> 
> Cheers
> 
> George in Oxford
> 
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

--- End Message ---
--- Begin Message ---
George,
    have a look at number_format()
(http://us2.php.net/manual/en/function.number-format.php). that in
combo with round() should do the trick.


On Fri, 3 Dec 2004 16:16:27 -0000, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> You could try concatenating a string of "0"s (�25.5000) on the end and using
> substr on the whole to get your �25.50.
> 
> $currency = $currency . "000";
> $currency = substr( $currency, 0, strpos($currency,'.') + 3 )
> 
> Neil Morgan
> 
> 
> 
> -----Original Message-----
> From: George Pitcher [mailto:[EMAIL PROTECTED]
> Sent: 03 December 2004 15:49
> To: [EMAIL PROTECTED]
> Subject: [PHP-WIN] displaying neat and tidy currency notation?
> 
> Hi,
> 
> I want to be able to display the results of some calculations as currency
> such as �25.50, but round($var,2) produces �25.5.
> 
> I've tried writing my own function but that just fouled up the calculation.
> 
> Any tips or suggestions?
> 
> Cheers
> 
> George in Oxford
> 
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
William Cox

email: [EMAIL PROTECTED]
blog: http://my-dimension.com

--- End Message ---
--- Begin Message ---
Hello George,

Try something like this:
$var = '25.5';
$var = sprintf("%.2f", $var);
echo $var;

GP> Hi,

GP> I want to be able to display the results of some calculations as currency
GP> such as �25.50, but round($var,2) produces �25.5.

GP> I've tried writing my own function but that just fouled up the calculation.

GP> Any tips or suggestions?

GP> Cheers

GP> George in Oxford




-- 
Best regards,
 re_action                            mailto:[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Thanks to all who responded. I did managed to write a working function last
night, but I've now dropped that one in favour of the sprintf() function.

Cheers

George

> -----Original Message-----
> From: re_action [mailto:[EMAIL PROTECTED]
> Sent: 3 December 2004 5:28 pm
> To: George Pitcher
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP-WIN] displaying neat and tidy currency notation?
>
>
> Hello George,
>
> Try something like this:
> $var = '25.5';
> $var = sprintf("%.2f", $var);
> echo $var;
>
> GP> Hi,
>
> GP> I want to be able to display the results of some calculations
> as currency
> GP> such as �25.50, but round($var,2) produces �25.5.
>
> GP> I've tried writing my own function but that just fouled up
> the calculation.
>
> GP> Any tips or suggestions?
>
> GP> Cheers
>
> GP> George in Oxford
>
>
>
>
> --
> Best regards,
>  re_action                            mailto:[EMAIL PROTECTED]
>
>

--- End Message ---

Reply via email to