Search code examples
pythonweb

Commas between numbers in Python or Django


hi this is my code for Percentage for the price of a product:

def get_discounted_malile_price(self):
    result = int(self.price - (self.price * (self.discount / 100)))
    round_result = round(result, 3)
    return round_result

and this is my result: enter image description here

i have add , for result number ,for example(1936000 -> 193.600.0) I would appreciate it if someone could help me.


Solution

  • Are you looking for this? https://stackoverflow.com/a/10742904/17320013

    value = 123456789
    print(f'{value:,}') # 123,456,789
    

    If yes, your code should be

    def get_discounted_malile_price(self) -> str:
        result = int(self.price - (self.price * (self.discount / 100)))
        round_result = f'{round(result, 3):,}'
        return round_result # NOTE: it returns str type