Connecting Tech Pros Worldwide Help | Site Map

Math Help Needed

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 01:08 AM
Ralph Freshour
Guest
 
Posts: n/a
Default 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...


  #2  
Old July 17th, 2005, 01:08 AM
Tom Thackrey
Guest
 
Posts: n/a
Default Re: Math Help Needed


On 14-Nov-2003, Ralph Freshour <ralph@primemail.com> wrote:
[color=blue]
> 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?[/color]

lookup round() or number_format()

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
  #3  
Old July 17th, 2005, 01:08 AM
timmeh
Guest
 
Posts: n/a
Default Re: Math Help Needed

round($aspect_rating, 4)

:)

"Ralph Freshour" <ralph@primemail.com> wrote in message
news:uvhbrvs0upfphjpie2gmcq18hk2c00jndc@4ax.com...[color=blue]
> 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...
>[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.