MATLAB: Is there a format in MATLAB to display numbers such that commas are automatically inserted into the display

insertMATLAB

For large numbers, it helps for reading purposes if the digits are separated by commas. For example, I would like MATLAB to display one billion as
1,000,000,000
rather than
1000000000

Best Answer

The ability to automatically format a number to display it with the commas inserted at the right places for easy reading is not available in MATLAB.
To work around this issue, the number needs to be converted to a string. Then, commas can be inserted between the string characters. The following function achieves this purpose:
function [str]=num2bank(num)
str = arrayfun(@(x) num2bankScalar(x) , num, 'UniformOutput', false)
end
function [str]=num2bankScalar(num)
num=floor(num*100)/100
str = num2str(num)
k=find(str == '.', 1)
if(isempty(k))
str=[str,'.00']
end
FIN = min(length(str),find(str == '.')-1)
for i = FIN-2:-3:2
str(i+1:end+1) = str(i:end)
str(i) = ','
end
end