<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Simplest way to remove trailing zeros of decimal numbers</title>
	<atom:link href="http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/</link>
	<description>The place where I share my experiments on my computer</description>
	<lastBuildDate>Fri, 03 Feb 2012 13:30:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: max4ever</title>
		<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/comment-page-1/#comment-19114</link>
		<dc:creator>max4ever</dc:creator>
		<pubDate>Thu, 02 Feb 2012 14:58:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sriunplugged.com/?p=123#comment-19114</guid>
		<description>echo (float) &quot;0.123000&quot;; // ==&gt; 0.123</description>
		<content:encoded><![CDATA[<p>echo (float) &#8220;0.123000&#8243;; // ==&gt; 0.123</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: web-developer</title>
		<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/comment-page-1/#comment-10619</link>
		<dc:creator>web-developer</dc:creator>
		<pubDate>Mon, 03 Oct 2011 09:19:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sriunplugged.com/?p=123#comment-10619</guid>
		<description>You should use this function, it works good with decimal (including 0.01 and 0.000) and integer (including 80):
[code]
function clean_num( $num ){
	$pos = strpos($num, &#039;.&#039;);
	if($pos === false) { // it is integer number
		return $num;
	}else{ // it is decimal number
		return rtrim(rtrim($num, &#039;0&#039;), &#039;.&#039;);
	}
}
[/code]</description>
		<content:encoded><![CDATA[<p>You should use this function, it works good with decimal (including 0.01 and 0.000) and integer (including 80):</p>
<pre class="brush: plain; title: ; notranslate">
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'), '.');
	}
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: bob</title>
		<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/comment-page-1/#comment-9625</link>
		<dc:creator>bob</dc:creator>
		<pubDate>Mon, 12 Sep 2011 22:22:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sriunplugged.com/?p=123#comment-9625</guid>
		<description>Sumesh - you are correct - but that wasn&#039;t the purpose of the function.  It is to be used on database fields that are of type decimal.  This function works perfectly.</description>
		<content:encoded><![CDATA[<p>Sumesh &#8211; you are correct &#8211; but that wasn&#8217;t the purpose of the function.  It is to be used on database fields that are of type decimal.  This function works perfectly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sumesh</title>
		<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/comment-page-1/#comment-6823</link>
		<dc:creator>Sumesh</dc:creator>
		<pubDate>Tue, 31 May 2011 10:04:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sriunplugged.com/?p=123#comment-6823</guid>
		<description>Please dont use this function it trims useful zeros. For eg. try clean_num(80). It will print 8!!!</description>
		<content:encoded><![CDATA[<p>Please dont use this function it trims useful zeros. For eg. try clean_num(80). It will print 8!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergiu</title>
		<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/comment-page-1/#comment-5546</link>
		<dc:creator>Sergiu</dc:creator>
		<pubDate>Tue, 12 Apr 2011 13:50:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sriunplugged.com/?p=123#comment-5546</guid>
		<description>I tried what you all said, but it didn&#039;t work...

here is what worked :D
function clean_num($number) {
	return trim(strrev(ltrim(strrev($number), 0)),&quot;.&quot;);
}</description>
		<content:encoded><![CDATA[<p>I tried what you all said, but it didn&#8217;t work&#8230;</p>
<p>here is what worked <img src='http://blog.sriunplugged.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
function clean_num($number) {<br />
	return trim(strrev(ltrim(strrev($number), 0)),&#8221;.&#8221;);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sasa</title>
		<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/comment-page-1/#comment-4661</link>
		<dc:creator>Sasa</dc:creator>
		<pubDate>Fri, 18 Mar 2011 16:20:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sriunplugged.com/?p=123#comment-4661</guid>
		<description>I don&#039;t know php very well, so I don&#039;t understand how decimal number can have leading or trailing zeros. In that case, that is not decimal number. Suppose that $num is string, try this code

function clean_num($num){
      return (string)(floatval($num));
}</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know php very well, so I don&#8217;t understand how decimal number can have leading or trailing zeros. In that case, that is not decimal number. Suppose that $num is string, try this code</p>
<p>function clean_num($num){<br />
      return (string)(floatval($num));<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charlie</title>
		<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/comment-page-1/#comment-2240</link>
		<dc:creator>Charlie</dc:creator>
		<pubDate>Tue, 14 Dec 2010 21:21:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sriunplugged.com/?p=123#comment-2240</guid>
		<description>This will also not work if the number is 0.00

In this case the function returns and empty string.

Therefore you should use this function:

function clean_num($num){  
if ($num==0) {return 0;}
return rtrim(rtrim($num, &#039;0&#039;), &#039;.&#039;);         } 

Also it will only strip trailing zeros, if you also want to strip leading zeros, use trim in place of rtrim.</description>
		<content:encoded><![CDATA[<p>This will also not work if the number is 0.00</p>
<p>In this case the function returns and empty string.</p>
<p>Therefore you should use this function:</p>
<p>function clean_num($num){<br />
if ($num==0) {return 0;}<br />
return rtrim(rtrim($num, &#8217;0&#8242;), &#8216;.&#8217;);         } </p>
<p>Also it will only strip trailing zeros, if you also want to strip leading zeros, use trim in place of rtrim.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: personal software</title>
		<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/comment-page-1/#comment-236</link>
		<dc:creator>personal software</dc:creator>
		<pubDate>Wed, 11 Aug 2010 11:34:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sriunplugged.com/?p=123#comment-236</guid>
		<description>One again, your articles is very good.thank you!very much.</description>
		<content:encoded><![CDATA[<p>One again, your articles is very good.thank you!very much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shankar nagvekar</title>
		<link>http://blog.sriunplugged.com/php/remove-trailing-zero-in-decimal/comment-page-1/#comment-229</link>
		<dc:creator>shankar nagvekar</dc:creator>
		<pubDate>Thu, 05 Aug 2010 10:27:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sriunplugged.com/?p=123#comment-229</guid>
		<description>Hi,
it will fail if the $num =0.01;
$var = trim(strrev(ltrim(strrev($number), &#039;0&#039;)),&#039;.&#039;);
try out this one

function clean_num($num){
    return trim(strrev(ltrim(strrev($number), &#039;0&#039;)),&#039;.&#039;);
        }</description>
		<content:encoded><![CDATA[<p>Hi,<br />
it will fail if the $num =0.01;<br />
$var = trim(strrev(ltrim(strrev($number), &#8217;0&#8242;)),&#8217;.');<br />
try out this one</p>
<p>function clean_num($num){<br />
    return trim(strrev(ltrim(strrev($number), &#8217;0&#8242;)),&#8217;.');<br />
        }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

