LoginSignup
7

More than 3 years have passed since last update.

Power Automate で四捨五入

Posted at

Power AutomateにはExcelでもお馴染みのRound, RoundDown/Up, Ceil/Floorなどの関数はありません。

でも比較的簡単に関数を組み合わせて作れるので、ご紹介します。

考え方

今回使うのは formatNumber関数 と int関数 または float関数です。

最終的に使う数式は以下のような形式です。

整数をにする.
 int(formatNumber(123.4567,'F0'))

※この結果は 123
小数点以下2桁を残すとき.
 float(formatNumber(123.4567,'F2'))

※3桁残すならこの結果は float(formatNumber(123.4567,'F3')) --> 123.457

最も重要な関数はformatNumberです。四捨五入自体はこの関数だけで完結していて float や int関数は後続処理で数値として扱いたい場合にのみ挿入してください。

関数解説

解説というほどでもありませんが。基本はformatNumber関数の使用例どおりです。

F0やF3は小数点以下0桁、3桁までは必ず残す、それ以下は丸めるというフォーマットです。
image.png

F0で小数点以下は0桁、つまり整数になるので、これを最後にint(...)でくくれば整数になりますし、float(...)でくくれば浮動小数点数が作られます。

※formatNumberだけだと、返す値は文字列です。

おわり

もう少し色々面倒な操作が必要かと思っていたらformatNumberが優秀でした。
Round、ceil、floorなどが Power Automate では用意されていないので、四捨五入したい場合にはこの組み合わせで使ってみて下さい。

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
7