5
3

More than 3 years have passed since last update.

CSV出力の0落ち対応

Posted at

はじめに

001などの先頭が0となっている数値をCSV出力しようとすると、0が省略され1と出力される問題の対応についてです。

対応

'="001"'

固定値の場合はこれで問題ないが、変数だと式展開されないので以下のようにする。

# ダブルクォートで囲むことに注意
%Q{="#{hoge}"}

Rubocop準拠すると、

# ダブルクォートで囲むことに注意
%(="#{hoge}")
5
3
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
5
3