Converting Float to Dollars and Cents

后端 未结 6 1084
北恋
北恋 2020-12-02 10:39

First of all, I have tried this post (among others): Currency formatting in Python. It has no affect on my variable. My best guess is that it is because I am using Python

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 11:00

    In python 3, you can use:

    import locale
    locale.setlocale( locale.LC_ALL, 'English_United States.1252' )
    locale.currency( 1234.50, grouping = True )
    

    Output

    '$1,234.50'
    

提交回复
热议问题