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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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"); ?> |
|
|||
|
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 |