LoginSignup
54
41

More than 5 years have passed since last update.

言語別 0埋め数字を作成する方法

Posted at

すぐ忘れるのでメモってみたらほとんど書き方が同じだった、っていう。

Java

コードそのものはシンプルだけど前後に書くことが多い…

System.out.println(String.format("%04d", 10));

Groovy

Javaよりお手軽だけど実行までにちょっとタイムラグがあるのが難点…

groovy -e "printf('%04d', 10)"

Ruby

rubyマジで自由すぎる。特に3つめ。

ruby -e "puts format('%04d', 10)"
ruby -e "printf('%04d', 10)"
ruby -e "puts '%04d' % 10"

shell

shellでも出来るとは思わなんだな。

printf %04d 10
54
41
0

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
54
41