2
1

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 1 year has passed since last update.

「会社法人等番号」を「法人番号」へと変換するRubyのコード

Last updated at Posted at 2018-01-22

コード

12桁の会社法人等番号の左端に一桁のチェックディジットを付加して13桁の法人番号を生成するためのRubyコード

# 12桁の会社法人等番号,0から始まることもあるので文字列で与えることにする
n12 = "000012050002"

# 13桁の法人番号
n13 = (9 - n12.split("").map(&:to_i).map.with_index {|d, i| 
  i.odd?? d : d * 2 }.inject(:+) % 9).to_s + n12
# => "7000012050002" 

参考

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?