Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP Decimal Point Help

Explorer ,
Aug 13, 2008 Aug 13, 2008
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!
TOPICS
Server side applications
361
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 13, 2008 Aug 13, 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...
Translate
LEGEND ,
Aug 13, 2008 Aug 13, 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!
>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 14, 2008 Aug 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 15, 2008 Aug 15, 2008
LATEST
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines