0
0

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.

EPPlus 出力したExcelの表示、対象セル選択時に見える実際の値と異なる原因

Posted at

EPPlus開発時、下記のような謎の現象がありました。

現象

セルの値が「0.8」に見えていますが、選択すると、0.80000099が表示されています。
截屏2023-04-10 17.23.25.png

対応方法

修正前

// 数値の値設定
ws.Cells[2, 1].Style.Numberformat.Format = "#,##0.0";
ws.Cells[2, 2].Value = float.Parse("0.8");

修正後

// 数値の値設定
ws.Cells[2, 1].Style.Numberformat.Format = "#,##0.0";
ws.Cells[2, 2].Value = double.Parse("0.8");

原因は、値の出力時、floatでキャストしたためです。
floatをdoubleに変更したら、正しく表示ができました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?