home.social

#thousandsseparator — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #thousandsseparator, aggregated by home.social.

  1. Today I learned that in Python you can print a floating point number with thousands separator and no floating point part with the f-string formatter `:integer_digits,.0f`.

    For instance:

    ```python
    print(f"{1234567891*1.1:15,.0f}")
    ```

    prints ` 1,358,024,680`, while

    ```python
    print(f"{1234567891*1.1:15,f}")
    ```

    prints `1,358,024,680.100000`.

    It also properly rounds up or down numbers, which is great.

    #TIL #TodayILearned #Python #FStrings #FloatingPoint #ThousandsSeparator