count number of digits after the decimal point

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ilikemoney
    New Member
    • Mar 2008
    • 1

    count number of digits after the decimal point

    i wanna know if theres a function or something that can count how many numbers there are after the decimal point using php...thanks
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I dont know if there's a function specified for this, but you could turn this into a function:
    [php]
    $_float = 1.9020441;
    $_float = explode(".", $_float);
    echo strlen($_float[1]);
    [/php]

    Regards :)

    Comment

    • satas
      New Member
      • Nov 2007
      • 82

      #3
      This variant is also possible:
      [PHP]$_float = 1.9020441123;
      print strcspn(strrev( $_float), '.');[/PHP]

      Regards.

      Comment

      Working...