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.
Recent Comments