amberlacsina
amberlacsina

Reputation: 3

How to format the display value of 0

How to format the value of 0 in such a way that it will display "0000.000000000000" using fprintf? I have %8.12f but it only displays 0.000000000000.

Upvotes: 0

Views: 68

Answers (1)

Wolfie
Wolfie

Reputation: 30046

You need to add a 0 character to instruct fprintf what the additional leading character should be, and then the width must be longer than the number of decimal places by the number of digits you wish to pad. i.e.

>> fprintf( '%017.12f\n', 0 )
  0000.000000000000

Upvotes: 4

Related Questions