php remove trailing zeros of a decimal number

Method to remove or strip trailing zeros of a decimal number:

<?php
function clean_num( $num ){
	$pos = strpos($num, '.');
	if($pos === false) { // it is integer number
		return $num;
	}else{ // it is decimal number
		return rtrim(rtrim($num, '0'), '.');
	}
}
?>

Works on numbers: 0.02=0.02; 4.000=4; 80=80.

VN:F [1.9.17_1161]
Rating: -1 (from 1 vote)

One thought on “php remove trailing zeros of a decimal number

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">