How to remove the excess zero after the decimal point in php
This article mainly introduces php how to remove the excess zero after the decimal point, the article is very detailed, has a certain reference value, interested friends must read it!
Methods: 1, use "decimal + 0", 2, use "floatval (decimal)", 3, use "rtrim (rtrim (decimal,'0'),'.'), 4, use" preg_replace ('/ [.] $/', preg_replace ('/ 0 decimal number).
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Today, we introduce several ways to remove the last zero of the decimal point:
Method 1. Add 0 directly.
Because PHP is a weak type, it can be converted directly into numbers by mathematical operations.
Output result:
100100.01100.1
Method 2. Convert to floating-point type using floatval ()
Output result:
100100.01100.1
Method 3. Use the rtrim () function
Output result:
100100.01100.1
Method 4. Use regular expressions
The regular expression states: / 0 destroy / remove the extra 0 / [.] $/ remove the end.
Output result:
100100.1100.010203 and above are all the contents of this article entitled "how to remove excess zeros after the decimal point in php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!