Math Help Needed

This is a discussion on Math Help Needed within the PHP Language forums, part of the PHP Programming Forums category; I'm doing some php math and need to divide a floating point number variable by only 4 decimal places - ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-15-2003
Ralph Freshour
 
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...

Reply With Quote
  #2 (permalink)  
Old 11-15-2003
Tom Thackrey
 
Posts: n/a
Default Re: Math Help Needed


On 14-Nov-2003, Ralph Freshour <ralph@primemail.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
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
Reply With Quote
  #3 (permalink)  
Old 11-15-2003
timmeh
 
Posts: n/a
Default Re: Math Help Needed

round($aspect_rating, 4)

:)

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



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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




All times are GMT +1. The time now is 07:04 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0