Round values after the decimal point
Useful helper function that rounds scalars, vectors or matrices smaller/bigger than zero at a defined place after the decimal point.
Needs two input arguments to work properly: out = sRound(val, precision)
Usage: out = sRound(val, prec)
Example1: a = sRound(0.46,1);
a = 0.5000
Example2: b = sRound(-5.478,2);
b = -5.4800
Example3: c = sRound([0.8236 2.6958 3.3171 0.9502 0.0364], 3);
c = 0.8240 2.6960 3.3170 0.9500 0.0360 0.34330
Example4: d = sRound([-0.1694 -1.4351 0.3925; -0.0522 -2.6 1.3433], 3);
d = -0.1690 -1.4350 0.3930
-0.0520 -2.6000 1.3430
Example5: e = sRound(3.5);
e = 4
This code should run with every MATLAB version.
引用格式
Tobias Otto (2024). Round values after the decimal point (https://www.mathworks.com/matlabcentral/fileexchange/31209-round-values-after-the-decimal-point), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!