Posted by & filed under Access.

○分類
VBA
○解説

  • モジュールを新規作成して、以下のコードを入力して保存します。

    Option Compare Database

    Public Function RoundUp(x As Currency, s As Integer) As Currency

    Dim w As Currency
    t = 10 ^ Abs(s)

    If x > 0 Then
    If s > 0 Then
    RoundUp = -Int(-x * t) / t
    Else
    RoundUp = -Int(-x / t) * t
    End If
    Else
    If s > 0 Then
    RoundUp = Int(x * t) / t
    Else
    RoundUp = Int(x / t) * t
    End If
    End If

    End Function

    Public Function RoundDown(x As Currency, s As Integer) As Currency

    Dim t As Currency
    t = 10 ^ Abs(s)

    If x > 0 Then
    If s > 0 Then
    RoundDown = Int(x * t) / t
    Else
    RoundDown = Int(x / t) * t
    End If
    Else
    If s > 0 Then
    RoundDown = -Int(-x * t) / t
    Else
    RoundDown = -Int(-x / t) * t
    End If
    End If

    End Function

    これで、
    RoundUp([数値],[桁数])
    RoundDown([数値],[桁数])
    が使えるはずです。試してみて下さい。
    (Netwanderer)

○私的意見

  • イケガミさんが「みんなのAccess備忘録」に書き込まれた、「Accessでの切上げ・四捨五入・切捨て関数」を参考にさせていただきました。
    ありがとうございました。>イケガミさん

    私はより精度をあげてみたのですが、いかがでしょうか?もし、不具合などあれば教えて下さい。

    それにしても、何でAccessにはこんな関数が用意されていないのか?(Netwanderer)

  • このような独自関数を公開していただけるのは、有り難いです。(ぱんち)
  • 偉いと思う。小生は算数ができないので、びっくりした。アクセスには大事な機能が無くて、不要な機能がやたら多い。つまり、使いにくい。(かぼ)
  • 同感です。
    何故、この機能が最初からないのか??不思議です。(Akira)
○関連リンク

書き込みはまだありません。

 

http://www.accessclub.jp/bibouroku/017.html

Comments are closed.