# HG changeset patch # User jwe # Date 1090941484 0 # Node ID d2a7208f35d40f260728505a6ac74a4cfa2b7b2b # Parent f69e95587ba39c4047073ffc76e78853cf5ecdcb [project @ 2004-07-27 15:18:04 by jwe] diff -r f69e95587ba3 -r d2a7208f35d4 scripts/ChangeLog --- a/scripts/ChangeLog Tue Jul 27 14:03:03 2004 +0000 +++ b/scripts/ChangeLog Tue Jul 27 15:18:04 2004 +0000 @@ -1,3 +1,8 @@ +2004-07-27 David Bateman + + * general/num2str.m: Also insert spaces in output when precision + argument is supplied. + 2004-07-23 David Bateman * general/bitcmp.m, general/bitget.m, general/bitset.m: New functions. diff -r f69e95587ba3 -r d2a7208f35d4 scripts/general/num2str.m --- a/scripts/general/num2str.m Tue Jul 27 14:03:03 2004 +0000 +++ b/scripts/general/num2str.m Tue Jul 27 15:18:04 2004 +0000 @@ -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)