Mercurial > hg > octave-nkf
diff scripts/general/num2str.m @ 4918:d2a7208f35d4
[project @ 2004-07-27 15:18:04 by jwe]
author | jwe |
---|---|
date | Tue, 27 Jul 2004 15:18:04 +0000 |
parents | 1c0442da75fd |
children | a1073eef650c |
line wrap: on
line diff
--- a/scripts/general/num2str.m +++ b/scripts/general/num2str.m @@ -44,7 +44,11 @@ if (isstr (arg)) fmt = strcat (arg, "%-+", arg(2:end), "i"); else - fmt = sprintf ("%%.%dg%%-+.%dgi", arg); + if (isnumeric (x) && round (x) == x && abs (x) < (10.^arg)) + fmt = sprintf ("%%%dd%%-+%ddi ", arg, arg); + else + fmt = sprintf ("%%%d.%dg%%-+%d.%dgi", arg+7, arg, arg+7, arg); + endif endif else ## Setup a suitable format string @@ -103,7 +107,11 @@ if (isstr (arg)) fmt = arg; else - fmt = sprintf ("%%.%dg", arg); + if (isnumeric (x) && round (x) == x && abs (x) < (10.^ arg)) + fmt = sprintf ("%%%dd ", arg); + else + fmt = sprintf ("%%%d.%dg", arg+7, arg); + endif endif else if (isnumeric (x) && round (x) == x && abs (x) < 1e10)