Home >Backend Development >PHP Problem >How to remove 0 after decimal point in php

How to remove 0 after decimal point in php

藏色散人
藏色散人Original
2020-08-11 10:20:146080browse

In PHP, you can directly use the "floatval" function to remove 0 after the decimal point. The syntax of the floatval function is "float floatval (mixed $var)". Using this function for conversion can not only retain valid decimal points, but also Remove the extra 0 at the end.

How to remove 0 after decimal point in php

Recommendation: "PHP Video Tutorial"

You can directly use floatval($arg) to convert, either Keep valid decimal points, and you can also remove the extra 0 at the end where arg is a variable.

floatval gets the floating point value of the variable

Syntax

float floatval ( mixed $var )

Returns the float value of the variable var.

Parameters

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

Return value: The floating point value of the var variable.

PHP version: PHP 4 >= 4.2.0, PHP 5, PHP 7

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