Use a
general program mode template.
The following template shows one way to do variable formatting.
Code:
program:
si = field('series_index');
index_val = test(
field('series'),
contains(si, '\.',
format_number(si, '{0:04.1f}'),
format_number(si, '{0:02d}')),
'');
finish_formatting(index_val, '', '', '.')
You will of course need to add the rest of the template to the result value, probably using the template function.
An alternate way to do it would be to generate the template string you want depending on the value of series and series_index, then return the result of evaluating that template. Which is easier for you depends on how you think.