| Description |
[strOut] = sigfig(num, nSigFig, dummy)
Rounds number to nSigFig number of significant figures and outputs a string Dummy in 3rd argument to have padded zeros
Lim Teck Por, 2006, 2008,2009
Apropos: mat2str, num2str, sprintf
This code serves as a workaround to rounding problems probably caused by converting from base 10 to base 2 prematurely (Note that this problem can also be found in C and python) and print zero padding:
num2str(3.15, 2)
mat2str(3.15, 2)
fprintf('%1.2g\n', 3.15)
sprintf('%1.2g\n', 3.15)
give 3.1 instead of 3.2 whereas an input of 3.75 gives 3.8.
sigfig(3.15, 2) gives "3.2"
sigfig(3.75, 2, []) gives "3.8e+0" |