Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remove the excess zero after the decimal point in php

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report