sigfigstr - printing with the appropriate number of sigfigs
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
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.