String formatting with fixed width

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Eisenhuth

    #1

    String formatting with fixed width

    Hello alltogether,

    is it possible to format stings with fixed width of let's say 7 character. T
    need a floating point with 3 chars before dot, padded with ' ' and 3 chars after
    dot, padded with '0'.

    Followingh is my approach
    >>f = 21.1
    >>s = "%.03f" % f
    >>s
    '21.100'

    But there are missing ' '. How can I get that? (For bigger numbers than 999 they
    might be cut: 1021 -021)

    Alexander
Working...