IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
format_number.m
Go to the documentation of this file.
1 %>@ingroup string
2 %>@file
3 %>brief Formats number to feature in a figure
4 %> @todo Introduce setup for this function. E.g. Nature requires comma separators.
5 %
6 %> @param n A number
7 %> @return s A string
8 function s = format_number(n)
9 
10 frac = n-floor(n);
11 s = '';
12 p = floor(n);
13 i = 1;
14 while 1
15  r = mod(p, 1000);
16  p = floor(p/1000);
17  if r == 0 && p == 0
18  if i == 1
19  s = ['0' s];
20  end;
21  break;
22  elseif p == 0
23  if ~isempty(s); s = [',' s]; end;
24  s = [sprintf('%d', r) s];
25  break;
26  else
27  if ~isempty(s); s = [',' s]; end;
28  s = [sprintf('%03d', r) s];
29  end;
30 end;
function format_number(in n)