Customized thousand separator for string type variable
<p>I want to format my string containing both decimal and floating point using thousand separator. I've tried:</p>

<pre><code>"{:,}".format() 
</code></pre>

<p>but it is not working with an argument of string type!</p>

<pre><code>&gt;&gt;&gt; num_str = "123456.230"
&gt;&gt;&gt; "{:,}".format(num_str)
Traceback (most recent call last):
File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ValueError: Cannot specify ',' with 's'.
&gt;&gt;&gt;
</code></pre>

<p>Googled for solution(s) but couldn't find any solution(s) that satisfy my needs.</p>

<p>My sample input: <code>"123456.0230"</code></p>

<p>My desired sample output to be: <code>"123,456.0230"</code></p>

<p>I wrote my own code which is as follows:</p>

<pre><code>input_str = ''
output_str = ''
lenth = 0

input_str = input("Input a number: ")

for i in input_str:
    if input_str[lenth] == '.':
        break
    lenth += 1

if lenth % 3 == 0:
    pos_separator = 3
else:
    pos_separator = lenth % 3

for i in range(0, lenth):
    if i == pos_separator:
        output_str += ',' + input_str[i]
        pos_separator += 3
    else:
        output_str += input_str[i]

output_str += input_str[lenth:]

print("Output String: ", output_str)
</code></pre>

<p>Sampe 1:</p>

<pre><code>&gt;&gt;&gt; Input a number: 123456.0230
&gt;&gt;&gt; Output String:  123,456.0230
</code></pre>

<p>Sample 2:</p>

<pre><code>&gt;&gt;&gt; Input a number: 12345.
&gt;&gt;&gt; Output String:  12,345.
</code></pre>

<p>Working okay but is there any other way better than this?</p>