This is a simple method I found to remove or strip trailing zeros of a decimal number. The function accepts the decimal number and return the trimmed value back. It removes all the redundant zeros in the number after the decimal point and if no number other than zero is present after the decimal point the decimal point too is removed.
function clean_num($num){
return trim(trim($num, '0'), '.');
}
The code is written in .php but can be converted to any other language by writing trim function also.
#1 by shankar nagvekar on August 5, 2010 - 3:57 pm
Hi,
it will fail if the $num =0.01;
$var = trim(strrev(ltrim(strrev($number), ’0′)),’.');
try out this one
function clean_num($num){
return trim(strrev(ltrim(strrev($number), ’0′)),’.');
}
#2 by personal software on August 11, 2010 - 5:04 pm
One again, your articles is very good.thank you!very much.