VBA

数値クラス

切り捨て

''' <summary>
''' 切り捨て
''' </summary>
''' <param name="Number">数値</param>
''' <param name="Digits">桁数</param>
''' <see>https://www.sejuku.net/blog/65924</see>
''' <reterns>切り捨て値</remarks>
Public Function RoundDown(ByVal Number As Double, ByVal Digits As Double) As Double
    RoundDown = Application.WorksheetFunction.RoundDown(Number, Digits)
End Function

切り上げ

''' <summary>
''' 切り上げ
''' </summary>
''' <param name="Number">数値</param>
''' <param name="Digits">桁数</param>
''' <see>https://www.sejuku.net/blog/65924</see>
''' <reterns>切り上げ値</reterns>
Public Function RoundUp(ByVal Number As Double, ByVal Digits As Double) As Double
    RoundUp = Application.WorksheetFunction.RoundUp(Number, Digits)
End Function

四捨五入

''' <summary>
''' 銀行丸め
''' </summary>
''' <param name="Number">数値</param>
''' <param name="Digits">桁数</param>
''' <see>https://www.sejuku.net/blog/66750</see>
''' <reterns>銀行丸め値</reterns>
Public Function RoundBank(ByVal Number As Double, ByVal Digits As Double) As Double
    RoundBank = Application.WorksheetFunction.Round(Number, Digits)
End Function
''' <summary>
''' 四捨五入
''' </summary>
''' <param name="Number">数値</param>
''' <param name="Format">フォーマット</param>
''' <reterns>四捨五入値</reterns>
''' <see>https://www.sejuku.net/blog/66750</see>
''' <remarks>Format関数を使う方法</remarks>
Public Function RoundFormat(ByVal Number As Double, ByVal Format As String) As Double
    RoundFormat = Format(Number, Format)
End Function
''' <summary>
''' 四捨五入
''' </summary>
''' <param name="Number">数値</param>
''' <param name="Digits">桁数</param>
''' <reterns>四捨五入値</reterns>
''' <see>https://www.sejuku.net/blog/66750</see>
''' <remarks>WorksheetFunctionを使う方法</remarks>
Public Function Round(ByVal Number As Double, ByVal Digits As Double) As Double
    Round = WorksheetFunction.Round(Number, Digits)
End Function

通貨フォーマット

''' <summary>
''' FormatCurrency 関数
''' </summary>
''' <param name="Expression">式</param>
''' <param name="NumDigitsAfterDecimal">桁数</param>
''' <param name="NumDigitsAfterDecimal">桁数</param>
''' <reterns>式</reterns>
''' <see>https://learn.microsoft.com/ja-jp/office/vba/language/reference/user-interface-help/formatcurrency-function</see>
Public Function StrFormatCurrency(ByVal Expression As Variant, Optional ByVal NumDigitsAfterDecimal As Long = -1, Optional ByVal IncludeLeadingDigit As VbTriState = vbUserDefault) As String
    StrFormatCurrency = FormatCurrency(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit)
End Function

コメント