Round values after the decimal point

版本 1.3.0.0 (1.6 KB) 作者: Tobias Otto
Rounding values at a defined place after the decimal point.
433.0 次下载
更新时间 2011/4/28

查看许可证

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 版本兼容性
创建方式 R2011a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Arithmetic Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.3.0.0

More user info and error handling

1.1.0.0

Added more user info

1.0.0.0