Code covered by the BSD License

### Highlights from Round to a Specified Number of Significant Digits

4.0
4.0 | 3 ratings Rate this file 23 Downloads (last 30 days) File Size: 4.07 KB File ID: #21225 Version: 1.0

# Round to a Specified Number of Significant Digits

### Edward Zechmann (view profile)

25 Aug 2008 (Updated )

Rounds a numeric array to a specified number of Significant Digits.

File Information
Description

sd_round stands for "Significant Digits Round".

This program rounds a 2-d matrix of numbers to a specified number of significant digits.

This program support five different styles of rounding the last digit: to the nearest integer, up, down, toward zero, and away from zero.

This program supports real and complex numbers.

The program outputs the rounded array, a cell string of the rounded matrix, the number of digits, to the left and right of the decimal place.

This program is useful for presenting scientific data that requires rounding to a specifid number of significant digits for publication.

Acknowledgements

Round2, Fix2, and Round2 inspired this file.

This file inspired Round With Significant Digits.

MATLAB release MATLAB 7.5 (R2007b)
13 May 2013 Will

### Will (view profile)

18 Apr 2012 Edward Zechmann

### Edward Zechmann (view profile)

Roundn is in the Mapping Toolbox which costs approximately \$1,000.00 for a single user license. It is much simpler; however, it has fewer features and costs \$1,000.00. The syntax for using roundn is reproduced from the Mathworks website to help anyone who reads this comment thread. Please let me know if a program with the simple syntax of Roundn would be of benefit to the Matlab Central Users Community.

roundn - Round to multiple of 10n
Syntax

roundn(x,n)
Description

roundn(x,n) rounds each element of x to the nearest multiple of 10n. The variable n must be scalar, and integer-valued. For complex x, the imaginary and real parts are rounded independently. For n = 0, roundn gives the same result as round. That is, roundn(x,0) == round(x).

Comment only
06 Apr 2012 Humayun Kathuria

### Humayun Kathuria (view profile)

Guys! Use "roundn" if you want to use a simple MATLAB built-in function.

19 Oct 2011 mathworks2011

### mathworks2011 (view profile)

23 Aug 2011 Peter

### Peter (view profile)

Is it a bug that:

sd_round(1.5000, 2)

==> 1.5000

I hoped for 1.5 as result.

Comment only
02 Sep 2008 Edward Zechmann

Dimitri, this submission fixed the error for rounding numbers less than 1. There is an additional example. The number of digits to the left and right of the decimal point is recalcualted after rounding, because rounding can affect the number of digits to the left and right of the decimal point. Please post a comment or send me an e-mail if you find any more bugs or have any questions. Thanks for your previous comments.

Comment only
02 Sep 2008 Dimitri Shvorob

.. So how does your submission improve on the older ones?

Comment only