使ããªãããã§ãã¾ã«ä½¿ãããå±é¢ããããã
ã§ãä¾ãã°äºæ¡ã®ã¼ãè©°ãã¨ããæç´ã«æ¸ãã¨ãããªæãã ãããï¼å ã ã®å¤ãæååãæ°å¤ãã§å¤ããã ãããã©ï¼ã
num = "0" if num.to_i < 10 num = "0" + num end
ãã ããªããé æªããªã¼ã£ã¦æã
Ruby ã§ãããªãã¨ãããªãã¡ããããªãã®ãï¼ãã¨æãã®ã¨åæã«ã Cè¨èªã ã£ãã sprintf ã¨ãã§ã§ããããããªãããªã¼ã¨æããæ¢ãã¦ã¿ãã
ããããããã®ã¾ãã¾ãºããªã§ sprintf ã£ã¦ã®ãããã
ããã使ãã¨ãããæ¸ããã
num = "0" num = sprintf("%02d", num)
num ãæ°åã§ãæååã§ããããªã«ãã£ã¦ããã模æ§ã
欲ãè¨ãã°ãç ´å£ã¡ã½ããçãªãã®ãããã¨è¯ããã ãã©ããã㯠num ã«å¤ã代å
¥ããæç¹ã§ sprintf ããã¾ãã°è¯ããã
åèï¼http://www.ruby-lang.org/ja/man/?cmd=view;name=sprintf%A5%D5%A5%A9%A1%BC%A5%DE%A5%C3%A5%C8