I use this regex to put thousand separators in a string:
while matchstr(mystr, '\(\d\)\(\d\{3}\)\(\D\|\s\|$\)') != ''
let mystr = substitute(mystr, '\(\d\)\(\d\{3}\)\(\D\|\s\|$\)', '\1.\2\3', 'g')
endwhile
For
let mystr = '2000000'
the code above gives
2.000.000
The problem is when there is a decimal separator, it also puts thousand separators in the fractional part of a number after the decimal separator (which is the comma hereafter).
For example,
let mystr = '2000000,2346'
leads to
2.000.000,2.346
while I want it to be
2.000.000,2346
I tried to adapt the above code but didn’t find a satisfiable solution.
Can anyone help me?
Use the following call to the
substitute()function instead of the wholeloop listed in the question.