Generic filters
Exact matches only
  • Show Number as Decimal – Else show first number only

    15th March 2019

    Php - Strings

    php codehaven

    Depending if your number has a half like 1.5, 4.5 by checking if the last digit is a zero or not, then it will either show the full number with a decimal showing (1.5 and 4.5) or otherwise it will only show the first number, as it does not need an empty zero. It can show the integer number (1 or 4) instead of (1.0 and 4.0).

    There are other ways of doing this, buts its also a good lesson in functions, and can see how it is returned to the function at the bottom.

    Was this code snippet helpful?