Home  >  Article  >  Backend Development  >  How to determine how many digits a number has in php?

How to determine how many digits a number has in php?

青灯夜游
青灯夜游Original
2019-10-15 14:23:5311909browse

PHP, "Hypertext Preprocessor", is a general open source scripting language. PHP is a scripting language executed on the server side. It is similar to C language and is a commonly used website programming language. PHP's unique syntax mixes C, Java, Perl, and PHP's own syntax. It is conducive to learning and widely used. It is mainly suitable for the field of web development.

How to determine how many digits a number has in php?

php method to determine how many digits a number is:

In PHP, you can first convert the number into an integer, Convert to a string and then check the length of the string to determine how many digits a number has.

Example:

<?php
  $a=120.567;
  echo strlen(floor($a));
?>

The execution result is

3

Explanation:

  • floor() function rounds down is the nearest integer.

  • php is a weakly typed language that can automatically convert data types according to changes in the running environment.

  • #strlen() function returns the length of the string. Returns the length of the string if successful, or 0 if the string is empty.

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of How to determine how many digits a number has in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn