Code covered by the BSD License  

Highlights from
Round to a Specified Number of Significant Digits

5.0

5.0 | 1 rating Rate this file 47 Downloads (last 30 days) File Size: 4.07 KB File ID: #21225

Round to a Specified Number of Significant Digits

by Edward Zechmann

 

25 Aug 2008 (Updated 26 Aug 2008)

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

| Watch this File

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

The author wishes to acknowledge the following in the creation of this submission:
round2, FIX2, ROUND2
This submission has inspired the following:
Round with significant digits

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
02 Sep 2008 Dimitri Shvorob

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

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.

23 Aug 2011 Peter

Is it a bug that:

sd_round(1.5000, 2)

==> 1.5000

I hoped for 1.5 as result.

19 Oct 2011 mathworks2011  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
round Edward Zechmann 22 Oct 2008 10:16:11
significant Edward Zechmann 22 Oct 2008 10:16:11
digits Edward Zechmann 22 Oct 2008 10:16:11
figures Edward Zechmann 22 Oct 2008 10:16:11
sig figs Edward Zechmann 22 Oct 2008 10:16:11
ceil Edward Zechmann 22 Oct 2008 10:16:11
fix Edward Zechmann 22 Oct 2008 10:16:11
precision Edward Zechmann 22 Oct 2008 10:16:11
round jorge cormane 23 Jul 2009 08:39:37
sig figs Silvia Wognum 01 Jun 2011 08:19:19

Contact us at files@mathworks.com