Created
September 1, 2014 05:18
-
-
Save tinybike/d8a26fd50b276908d4d5 to your computer and use it in GitHub Desktop.
insert commas into numbers for display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function comma_N = commatic(N) | |
% COMMATIC Insert commas into integers, e.g. 1234567 -> '1,234,567'. | |
% (c) Jack Peterson, 4/29/2013 | |
N = num2str(N); | |
num_digits = length(N); | |
comma_N = ''; | |
for j = 1:num_digits | |
comma_N = strcat(N(num_digits-j+1),comma_N); | |
if ~mod(j,3) | |
comma_N = strcat(',',comma_N); | |
end | |
end | |
if strcmp(comma_N(1), ',') | |
comma_N(1) = []; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment