sigfigstr - printing with the appropriate number of sigfigs

Version 1.0.1 (1.07 KB) by Eric Homer
This function is aimed at creating formatted strings of numbers with the appropriate number of significant figures, whether large or small.
1 Download
Updated 12 Feb 2021

View License

This function formats strings based on the desired number of significant figures rather than the number of decimal places. It is inspired by work on stack overflow (https://stackoverflow.com/questions/21354701/matlab-fprintf-to-keep-significant-figures-and-rightmost-zeroes).

Here is an example of it in action
>> sigfigstr(.000012431634,3)
ans = '0.0000124'
>> sigfigstr(26666,3)
ans = '26700'

I welcome any feedback or notes of when it doesn't work.

Cite As

Eric Homer (2024). sigfigstr - printing with the appropriate number of sigfigs (https://www.mathworks.com/matlabcentral/fileexchange/87327-sigfigstr-printing-with-the-appropriate-number-of-sigfigs), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2020b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.1

Fixed a small bug

1.0.0