Home  >  Article  >  Backend Development  >  How to remove excess 0 in php

How to remove excess 0 in php

藏色散人
藏色散人Original
2021-03-11 10:15:052484browse

In PHP, you can directly remove excess 0s through the "floatval()" function. This function can retain valid decimal points and can also remove excess 0s at the end. Its syntax is "float floatval(mixed $var) ".

How to remove excess 0 in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php remove the 0 after the decimal point and keep non-zero

Use floatval($arg) directly to convert, which can not only retain the valid decimal point, but also remove the extra 0 at the end, where arg is a variable.

floatval —Get the floating point value of the variable

Syntax

float floatval ( mixed $var )

Return the float value of the variable var.

Parameters

var var can be any scalar type. You cannot use floatval() with arrays or objects.

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to remove excess 0 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