Zahl überprüfen

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Zahl überprüfen

    Wie kann ich mit PHP überprüfen, ob eine Zahl natürlich ist oder eine Kommastelle hat?
    *blubb*

  • #2
    Re: Zahl überprüfen

    if($zahl == floor($zahl))?
    if($zahl == (int)$zahl)?
    I don't believe in rebirth. Actually, I never did in my whole lives.

    Comment


    • #3
      Hi,

      es reicht zu prüfen ob es sich um eine natürliche zahl handelt.

      PHP Code:
      ($zahl == floor($zahl) && $zahl 0
      greets
      (((call/cc call/cc) (lambda (x) x)) "Scheme just rocks! and Ruby is magic!")

      Comment


      • #4
        @closure - was ist denn z.b. mit 5.0?

        ich würd's mit nem regex machen:
        preg_match('/^[1-9]\d*$/', $zahl)

        Comment


        • #5
          Hi,

          5.0 ist eine natürliche zahl und wird auch als solche erkannt. Die darstellung
          ist lediglich eine andere. In diesem fall also als dezimalzahl. Wobei man
          hier natürlich vorsichtig sein muss. Es kann auch eine auf kommastellen
          begrenzte nicht natürliche zahl sein.

          Ich denke allerdings der das dieser sonderfall hier nicht ins gewicht fällt.

          greets
          (((call/cc call/cc) (lambda (x) x)) "Scheme just rocks! and Ruby is magic!")

          Comment

          Working...
          X