# Math Help Needed - PHP Development

I'm doing some php math and need to divide a floating point number variable by only 4 decimal places - when I do the following: \$aspect_ratio = 942 / 760; \$new_height = \$target_width * \$aspect_ratio; In PHP \$aspect_ratio claculates to 1.2394736842105 but for my purposes I need only 1.2394 How can I limit the decimals to just 4 places? Thanks......

1. ## Math Help Needed

I'm doing some php math and need to divide a floating point number
variable by only 4 decimal places - when I do the following:

\$aspect_ratio = 942 / 760;
\$new_height = \$target_width * \$aspect_ratio;

In PHP \$aspect_ratio claculates to 1.2394736842105 but for my purposes
I need only 1.2394

How can I limit the decimals to just 4 places?

Thanks...

Ralph Freshour Guest

2. ## Re: Math Help Needed

On 14-Nov-2003, Ralph Freshour <ralphprimemail.com> wrote:
> I'm doing some php math and need to divide a floating point number
> variable by only 4 decimal places - when I do the following:
>
> \$aspect_ratio = 942 / 760;
> \$new_height = \$target_width * \$aspect_ratio;
>
> In PHP \$aspect_ratio claculates to 1.2394736842105 but for my purposes
> I need only 1.2394
>
> How can I limit the decimals to just 4 places?
lookup round() or number_format()

--
Tom Thackrey
[url]www.creative-light.com[/url]
tom (at) creative (dash) light (dot) com
do NOT send email to [email]jamesbutlerwillglen.net[/email] (it's reserved for spammers)
Tom Thackrey Guest

3. ## Re: Math Help Needed

round(\$aspect_rating, 4)

:)

"Ralph Freshour" <ralphprimemail.com> wrote in message
news:uvhbrvs0upfphjpie2gmcq18hk2c00jndc4ax.com...
> I'm doing some php math and need to divide a floating point number
> variable by only 4 decimal places - when I do the following:
>
> \$aspect_ratio = 942 / 760;
> \$new_height = \$target_width * \$aspect_ratio;
>
> In PHP \$aspect_ratio claculates to 1.2394736842105 but for my purposes
> I need only 1.2394
>
> How can I limit the decimals to just 4 places?
>
> Thanks...
>

timmeh Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•