Rounding Off Number(s) to Specified Significant Figures

version 1.0.0.0 (1.3 KB) by Yuzo Toya
Round off number(s) to specified significant figures, using two simple/powerful MATLAB functions.

3K Downloads

Updated 28 Apr 2009

View License

spa_sf Rounding Off Number(s) to Certain Significant Figures

N = spa_sf(X,SF) is the rounded off number(s) of X with the specified significant figures SF. X could be a scalar or a vector; however, SF must be a scalar.

Example 1)
X = 3.14159265359;
SF = 3;
N = spa_sf(X,SF)

> N = 3.1400

Example 2)
X = 3.14159265359; X=[X,X*2;X*3,X*4];
SF = 3;
N = spa_sf(X,SF)

> N =
3.1400 6.2800
9.4200 12.6000

See also: num2str, str2num

* I hope it would be of any help.

Cite As

Yuzo Toya (2022). Rounding Off Number(s) to Specified Significant Figures (https://www.mathworks.com/matlabcentral/fileexchange/23949-rounding-off-number-s-to-specified-significant-figures), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!