Money_Format Error with Calculated Variable

This is a discussion on Money_Format Error with Calculated Variable within the PHP General forums, part of the PHP Programming Forums category; I'm trying to calculate a value then display as currency but when I send my variable to format it ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-10-2006
bdog4@hotmail.com
 
Posts: n/a
Default Money_Format Error with Calculated Variable

I'm trying to calculate a value then display as currency but when I
send my variable to format it says "expecitng double, sent string" how
can I do this

<?php
$total = $row_Totals['InvTotals'];
$payments = 0;
if ($row_Payments) $payments = $row_Payments['tPayments'];
$total = $total - $payments;
echo money_format('%i', (int)$total . "\n"); ?>

Reply With Quote
  #2 (permalink)  
Old 02-10-2006
Ken Hagans
 
Posts: n/a
Default Re: Money_Format Error with Calculated Variable

On Thu, 09 Feb 2006 19:04:47 -0800, bdog4 wrote:

> I'm trying to calculate a value then display as currency but when I send
> my variable to format it says "expecitng double, sent string" how can I do
> this
>
> <?php
> $total = $row_Totals['InvTotals'];
> $payments = 0;
> if ($row_Payments) $payments = $row_Payments['tPayments']; $total = $total
> - $payments;
> echo money_format('%i', (int)$total . "\n"); ?>


bdog,

Since you're getting an error, I will assume that you're not trying to
use money_format on a Windows platform (it's not defined on Windows).

With that out of the way, let's look at money_format argument. You're
including some values that are confusing the function.

First, (int)$total would actually be written int($total) BUT, you don't
want this argument at all. The int() function will convert your floating
decimal value ($total) into an integer. This will cause money_format() to
fail.

Next, the ."\n" needs to be moved outside of the parenthesis. You're
apparently trying to add a linefeed after the result of money_format. So,
your formula should look like:

echo money_format('%i', $total)."\n";

Try that.

-Ken

--
KG Hagans Professional Services Group
Columbus, Ohio


Reply With Quote
  #3 (permalink)  
Old 02-10-2006
bdog4@hotmail.com
 
Posts: n/a
Default Re: Money_Format Error with Calculated Variable

That was it, thanks for the help Ken.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:59 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0