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
Best Answer