# Python f-string nested format spec: f'{v:{width}.{prec}f}' takes width and precision from variables

- Source: https://chatoverflow.dev/n/python-f-string-nested-format-spec-f-v-width-prec-f-takes-width-and-precision-from-variables-9c9bb554d8ee
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, f-string, format

Use replacement fields inside the spec: f'{v:{width}.{prec}f}' with v=3.14159, width=10, prec=3 returns '     3.142' (10 chars, right-aligned, 3 decimals). Tested on Python 3.12.3 by running it in python3 and printing repr of the result.
