アクセス担当のまみです。
数値を扱うときって、合計したり、平均したり、割ってみたりと色々ありますね。
データをどんなふうに分析したいかで、計算方法が変わるのですが、端数の処理方法も四捨五入、切り捨て、切り上げと色々あります。
そんな端数処理を毎回計算するのは大変だけど、関数を使って計算してくれるととっても助かりますね。
今回は、端数処理を行ってくれる関数についてお伝えしますね。
Contents
クエリを使って切り捨てをする
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
切り捨てを行ってくれる関数はInt関数とFix関数の2つあります。
どちらも正の数の切り捨て結果は同じで、負の数の扱いが違います。
Fix(数値)
どちらも小数点以下を切り捨ててくれる関数です。
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
使用するテーブル
「T_サンプルデータ」
![](https://pc.arthhuman.com/wp-content/uploads/2018/12/cmb633.jpg)
クエリで、Int関数、Fix関数をそれぞれ使用してみましょう。
![](https://pc.arthhuman.com/wp-content/uploads/2018/11/cmb561.jpg)
リボンの①「作成」タブから②「クエリデザイン」を選択し「T_サンプルデータ」を選びます。
![](https://pc.arthhuman.com/wp-content/uploads/2018/12/cmb634.jpg)
フィールドに「Int切り捨て: Int([数値])」と「Fix切り捨て: Fix([数値])」を入力しましょう。
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
クエリの結果
![](https://pc.arthhuman.com/wp-content/uploads/2018/12/cmb635.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
小数点以下第2位の切り捨てはInt関数の場合「 Int([数値]*10)/10」になります。(Fix関数だと「Fix([数値]*10)/10」)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
※Fix関数は「Fix([数値]/10)*10」
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
クエリは「Q_切り捨て」と名前をつけておきましょう。
[quads id=2]
クエリを使って四捨五入をする
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
「Q_切り捨て」をコピーして「Q_四捨五入」を作成し、デザインビューで開きましょう。
フィールドに「Int四捨五入: Int([数値])+0.5」と「Fix四捨五入: Fix([数値])+0.5」を入力しましょう。
![](https://pc.arthhuman.com/wp-content/uploads/2018/12/cmb636.jpg)
データシートビューで確認してみましょう。
クエリの結果
![](https://pc.arthhuman.com/wp-content/uploads/2018/12/cmb637.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
Fix四捨五入: Fix([数値]+0.5*Sgn([数値]))
![](https://pc.arthhuman.com/wp-content/uploads/2018/12/cmb638.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
クエリの結果
![](https://pc.arthhuman.com/wp-content/uploads/2018/12/cmb639.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
クエリは「Q_四捨五入」と名前をつけておきましょう。
クエリを使って切り上げをする
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/kyara1-r.jpg)
Int切り上げ: IIf([数値]=Int([数値]),Int([数値]),Int([数値]+1))
![](https://pc.arthhuman.com/wp-content/uploads/2018/12/cmb640.jpg)
クエリの結果
![](https://pc.arthhuman.com/wp-content/uploads/2018/12/cmb641.jpg)
![](https://pc.arthhuman.com/wp-content/uploads/2018/10/hatenakun2.jpg)
クエリは「Q_切り上げ」と名前をつけておきましょう。
まとめ
アクセスって切り捨ての関数しかないので、四捨五入や切り上げをする時にはちょっと工夫が必要です。
端数処理ができると、色々なデータの処理が自動でできるので便利ですね。
ぜひ活用してくださいね!