Format float

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

    Format float

    Hi all,

    Is it possible to adjust the number of digits in a float?

    For example $test = 1/3; echo ($test); gives 0.33333333.. But i only
    want 0.33
    Is there a function or do i have to use round($test*100 )/100

    Thanx,
    WJ
  • Rik

    #2
    Re: Format float

    WJ Zeeuwen wrote:[color=blue]
    > Hi all,
    >
    > Is it possible to adjust the number of digits in a float?
    >
    > For example $test = 1/3; echo ($test); gives 0.33333333.. But i only
    > want 0.33
    > Is there a function or do i have to use round($test*100 )/100[/color]

    I'd use round($test,2);
    Also possible is number_format() ;

    Grtz,
    --
    Rik Wasmus


    Comment

    • Jerry Stuckle

      #3
      Re: Format float

      WJ Zeeuwen wrote:[color=blue]
      > Hi all,
      >
      > Is it possible to adjust the number of digits in a float?
      >
      > For example $test = 1/3; echo ($test); gives 0.33333333.. But i only
      > want 0.33
      > Is there a function or do i have to use round($test*100 )/100
      >
      > Thanx,
      > WJ[/color]

      If all you want to do is display the value 0.33 without actually changing the
      number (which will affect future math operations), you can use

      printf("%01.2f" , 0.33);

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      Working...