Home > vbmeg > functions > common > utility > vb_util_get_digit_number.m

vb_util_get_digit_number

PURPOSE ^

return digit number

SYNOPSIS ^

function [ digit_num ] = vb_util_get_digit_number( target_num )

DESCRIPTION ^

 return digit number

 [usage]
   [ digit_num ] = vb_get_digit_number( target_num )

 [input]
   target_num : <required> target number <<integer>>

 [output]
   digit_num  : digit number of 'target_num'
              : e.g.
              :  23456 -> 5

 [note]
   target_num must be integer.
   Decimal number is truncated.

 [history]
   2012-03-16 (Sako) initial version

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ digit_num ] = vb_util_get_digit_number( target_num )
0002 % return digit number
0003 %
0004 % [usage]
0005 %   [ digit_num ] = vb_get_digit_number( target_num )
0006 %
0007 % [input]
0008 %   target_num : <required> target number <<integer>>
0009 %
0010 % [output]
0011 %   digit_num  : digit number of 'target_num'
0012 %              : e.g.
0013 %              :  23456 -> 5
0014 %
0015 % [note]
0016 %   target_num must be integer.
0017 %   Decimal number is truncated.
0018 %
0019 % [history]
0020 %   2012-03-16 (Sako) initial version
0021 
0022 % --- CHECK ARGUMENTS --- %
0023 if ~exist('target_num', 'var'), target_num = []; end
0024 [target_num] = inner_check_arguments(target_num);
0025 
0026 % --- MAIN PROCEDURE --------------------------------------------------------- %
0027 %
0028 if target_num == 0
0029   digit_num = 0;
0030   return;
0031 end
0032 
0033 digit_num = 1;
0034 while 1
0035   target_num = target_num / 10;
0036   if target_num < 1
0037     break;
0038   else
0039     digit_num = digit_num + 1;
0040   end
0041 end
0042 return;
0043 %
0044 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0045 
0046 % --- INNER FUNCTIONS -------------------------------------------------------- %
0047 %
0048 % --- inner_check_arguments()
0049 %
0050 function [target_num] = inner_check_arguments(target_num)
0051 func_ = mfilename;
0052 if isempty(target_num)
0053   error('(%s) target_num is a required parameter', func_);
0054 end
0055 
0056 if ~isnumeric(target_num)
0057   error('(%s) target_num must be integer', func_);
0058 end
0059 
0060 target_num = abs(target_num);
0061 target_num = floor(target_num);
0062 return;
0063 %
0064 % --- end of inner_check_arguments()
0065 %
0066 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0067 
0068 % --- END OF FILE --- %

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005