A math puzzler for you

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

    #1

    A math puzzler for you

    I have a php code that generates numbers. sometimes is generates whole
    numbers but most of the time decimals. How can I, when it generates a
    whole number, convert the number to n.0
    where n is the whole number?

    For example 23 := 23.0

  • Justin Koivisto

    #2
    Re: A math puzzler for you

    monomaniac21 wrote:[color=blue]
    > I have a php code that generates numbers. sometimes is generates whole
    > numbers but most of the time decimals. How can I, when it generates a
    > whole number, convert the number to n.0
    > where n is the whole number?
    >
    > For example 23 := 23.0[/color]

    $int = 23;

    $float = floatval($int);

    If you mean for just output purposes:
    printf('%.1f',$ int);

    --
    Justin Koivisto, ZCE - justin@koivi.co m

    Comment

    • Geoff Berrow

      #3
      Re: A math puzzler for you

      Message-ID: <1144438457.389 536.252430@i40g 2000cwc.googleg roups.com> from
      monomaniac21 contained the following:
      [color=blue]
      >I have a php code that generates numbers. sometimes is generates whole
      >numbers but most of the time decimals. How can I, when it generates a
      >whole number, convert the number to n.0
      >where n is the whole number?[/color]


      $var=23;

      print number_format($ var,1);

      //outputs 23.0
      --
      Geoff Berrow (put thecat out to email)
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      Working...