> For the complete documentation index, see [llms.txt](https://manuals.i-reporter.jp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manuals.i-reporter.jp/create-a-form/prepare-the-formexcelfile/excelfunctions/excelfunctionroundingerror-and-workaround.md).

# EXCEL関数 小数計算の誤差と回避方法

## **誤差**

i-ReporterのEXCEL関数機能で小数計算をした結果と、Excel上の計算結果との間に誤差が発生することがあります。\
誤差が発生する原因は、i-Reporterが内部で二進数計算をしているためです。

Excelでも計算中に誤差が発生しますが、計算結果は補正されています。

この補正アルゴリズムの条件が複雑であるため、i-ReporterとExcelとで小数計算結果を完全一致させることができません。

{% hint style="info" %}
【参考：Microsoft Learn】 ※外部サイト

[浮動小数点演算が Excel で不正確な結果をもたらす可能性がある](https://docs.microsoft.com/ja-jp/office/troubleshoot/excel/floating-point-arithmetic-inaccurate-result)
{% endhint %}

{% hint style="success" %}
【例】Excelでの計算誤差

* 3/10 ー　2/10 ー　1/10　= 0
* (3/10 ー　2/10 ー　1/10) = -2.77556E-17  ※-0.0000000000000000277556

このように、括弧の有無で誤差の補正が変化します。\
i-Reporterでの計算結果は、上記２つとも"0"となります。
{% endhint %}

## **回避方法**

Excelとの誤差は、ROUND関数を利用して四捨五入することで回避可能です。

{% hint style="success" %}
【例】

* **Excelの場合**\
  1/3＋1/3+1/3=1
* **i-Reporterの場合**\
  1/3＋1/3+1/3=0.9999999999…

「1/3＋1/3+1/3の計算結果をIF関数で”1”と判定させたい」場合、

IF(1/3＋1/3+1/3 = 1, “OK”,”NG”)\
＝”NG”となる（Excelは”OK”）

↓

IF(ROUND(1/3＋1/3+1/3, 5) = 1, “OK”,”NG”)\
＝”OK”となる
{% endhint %}
