Home > FMAToolbox > Helpers > int2zstr.m

int2zstr

PURPOSE ^

int2zstr - Convert integer to zero-padded string.

SYNOPSIS ^

function s = int2zstr(n,digits)

DESCRIPTION ^

int2zstr - Convert integer to zero-padded string.

  USAGE

    s = int2zstr(n,digits)

    n              integer to convert
    digits         optional total number of digits

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %int2zstr - Convert integer to zero-padded string.
0002 %
0003 %  USAGE
0004 %
0005 %    s = int2zstr(n,digits)
0006 %
0007 %    n              integer to convert
0008 %    digits         optional total number of digits
0009 %
0010 
0011 % Copyright (C) 2012 by Michaƫl Zugaro
0012 %
0013 % This program is free software; you can redistribute it and/or modify
0014 % it under the terms of the GNU General Public License as published by
0015 % the Free Software Foundation; either version 3 of the License, or
0016 % (at your option) any later version.
0017 
0018 function s = int2zstr(n,digits)
0019 
0020 % Check number of parameters
0021 if nargin < 1,
0022   error('Incorrect number of parameters (type ''help <a href="matlab:help int2zstr">wrap</a>'' for details).');
0023 end
0024 
0025 % Convert to string
0026 s = int2str(n);
0027 
0028 % Pad if necessary
0029 if nargin < 2, return; end
0030 l = digits-length(s);
0031 if l <= 0, return; end
0032 s = [ones(1,l)*'0' s];

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005