Skip to main content
Inspiring
August 14, 2008
Answered

PHP Decimal Point Help

  • August 14, 2008
  • 3 replies
  • 359 views
I am working on a payroll application written in PHP and MYSQL.

I need to find a way to make the final pay amount render correctly from two variable.

The code (shown below) I have written in PHP for the $pay_amount is causing the deciaml to read as $75.5 instead of $75.50.

$pay_amount = $total_hours * $hrate;

Can someone please help me find a way to make the $pay_amount decial point / currency read correctly?

PS - I am new to PHP but catching on quickly - so try to make the responce as easy to understand!

Thank in advance!
This topic has been closed for replies.
Correct answer Newsgroup_User
$pay_amount = number_format($total_hours * $hrate, 2);

--
Ken Ford
Adobe Community Expert Dreamweaver/ColdFusion
Fordwebs, LLC
http://www.fordwebs.com


"bcounts" <webforumsuser@macromedia.com> wrote in message
news:g7vuh8$mo9$1@forums.macromedia.com...
>I am working on a payroll application written in PHP and MYSQL.
>
> I need to find a way to make the final pay amount render correctly from
> two
> variable.
>
> The code (shown below) I have written in PHP for the $pay_amount is
> causing
> the deciaml to read as $75.5 instead of $75.50.
>
> $pay_amount = $total_hours * $hrate;
>
> Can someone please help me find a way to make the $pay_amount decial point
> /
> currency read correctly?
>
> PS - I am new to PHP but catching on quickly - so try to make the responce
> as
> easy to understand!
>
> Thank in advance!
>

3 replies

Inspiring
August 15, 2008
Michael Fesser escreveu:
> .oO(bcounts)
>
>> I am working on a payroll application written in PHP and MYSQL.
>>
>> I need to find a way to make the final pay amount render correctly from two
>> variable.
>>
>> The code (shown below) I have written in PHP for the $pay_amount is causing
>> the deciaml to read as $75.5 instead of $75.50.
>>
>> $pay_amount = $total_hours * $hrate;
>>
>> Can someone please help me find a way to make the $pay_amount decial point /
>> currency read correctly?
>
> number_format() or printf() with a '%f' placeholder.
>
> Micha
----
Additionaly you can use money_format() [undefined in Windows].
maney_format() is compatible with the locale.
-----
zerof
Inspiring
August 14, 2008
.oO(bcounts)

>I am working on a payroll application written in PHP and MYSQL.
>
> I need to find a way to make the final pay amount render correctly from two
>variable.
>
> The code (shown below) I have written in PHP for the $pay_amount is causing
>the deciaml to read as $75.5 instead of $75.50.
>
> $pay_amount = $total_hours * $hrate;
>
> Can someone please help me find a way to make the $pay_amount decial point /
>currency read correctly?

number_format() or printf() with a '%f' placeholder.

Micha
Newsgroup_UserCorrect answer
Inspiring
August 14, 2008
$pay_amount = number_format($total_hours * $hrate, 2);

--
Ken Ford
Adobe Community Expert Dreamweaver/ColdFusion
Fordwebs, LLC
http://www.fordwebs.com


"bcounts" <webforumsuser@macromedia.com> wrote in message
news:g7vuh8$mo9$1@forums.macromedia.com...
>I am working on a payroll application written in PHP and MYSQL.
>
> I need to find a way to make the final pay amount render correctly from
> two
> variable.
>
> The code (shown below) I have written in PHP for the $pay_amount is
> causing
> the deciaml to read as $75.5 instead of $75.50.
>
> $pay_amount = $total_hours * $hrate;
>
> Can someone please help me find a way to make the $pay_amount decial point
> /
> currency read correctly?
>
> PS - I am new to PHP but catching on quickly - so try to make the responce
> as
> easy to understand!
>
> Thank in advance!
>