17
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

printf 整数の桁そろえ、0埋め メモ

Posted at

oFいじっててつまずいたのでメモです。
C言語ばりばりの方々には基礎すぎるかもですが

覚え方→ %桁数d

sample
    int a = 10000;
    int b = 500;

    printf("aは%5dです",a); // aは10000です
    printf("bは%5dです",b); // bは  500です

0埋めしたい場合
覚え方→ %0桁数d

sample

    int a = 10000;
    int b = 500;

    printf("aは%05dです",a); // aは10000です
    printf("bは%05dです",b); // bは00500です
    printf("bは%04dです",b); // bは0500です
17
12
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?