Why are you doing all that work? Qt already has what you're looking for if you use QString::toDouble and QString::number(). If you set your locale manually before calling toDouble() then you can use the comma decimal notation without replacing anything.
You could also create a string template like QString("[%1,%2]")
and then use the double
version of QString::arg
.