Home > matlabmk > rnd_orderofmag.m

rnd_orderofmag

PURPOSE ^

function rounded_val=rnd_orderofmag(val)

SYNOPSIS ^

function rounded_val=rnd_orderofmag(val)

DESCRIPTION ^

function rounded_val=rnd_orderofmag(val)

 Rounds val to lowest non-zero digit

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function rounded_val=rnd_orderofmag(val)
0002 %function rounded_val=rnd_orderofmag(val)
0003 %
0004 % Rounds val to lowest non-zero digit
0005 
0006 orig_val=val;
0007 val=abs(val);
0008 if val>=1
0009     ord=1;
0010     val=floor(val/10);
0011     while val>=1,
0012         ord=ord*10;
0013         val=floor(val/10);
0014     end
0015 else
0016     ord=1/10;
0017     val=val*10;
0018     while val<1,
0019         ord=ord/10;
0020         val=val*10;
0021     end
0022 end
0023 
0024 rounded_val=round(orig_val/ord)*ord;

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005