Let's say I have a number like this:
8,741 or 8,741,291
How can I use python to multiply that number by 2, and then put commas back into it? I want the python function to return
17,482 and 17,482,582, in a string format.
my_str = '1,255,000'
my_num = int(my_str.replace(',','')) #replace commas with nothing
this will return my_num = 1255000
result = my_num * 2
import locale
locale.setlocale(locale.LC_ALL, 'en_US')
my_str = locale.format("%d", result, grouping=True)
this will return->my_str='2,510,000'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With