Math Help Needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    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...

  • Tom Thackrey

    #2
    Re: Math Help Needed


    On 14-Nov-2003, Ralph Freshour <ralph@primemai l.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

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    • timmeh

      #3
      Re: Math Help Needed

      round($aspect_r ating, 4)

      :)

      "Ralph Freshour" <ralph@primemai l.com> wrote in message
      news:uvhbrvs0up fphjpie2gmcq18h k2c00jndc@4ax.c om...[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]


      Comment

      Working...