四捨五入

文法
ROUND ( number [, integer] )
数値 number を小数第 integer 位(省略時は 0)に四捨五入した値を戻す。
引数
number 四捨五入を行う数値(数値式)
integer 丸め処理をする位 (デフォルト0)

使用例

select
round(123.4544,0) ,
round(123.4544,1) ,
round(123.4544,2) ,
round(123.4544,3) ,
round(123.4544,-1) ,
round(123.4544,-2)
from dual

結果
ROUND関数

Imports Oracle.DataAccess.Client

Public Class frmSQL_Trim

    Private dt As DataTable = Nothing

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Try
            Using da As New OracleDataAdapter(TextSQL.Text.Trim, clsGlobal.gConnetionString)

                dt = New DataTable
                da.Fill(dt)

                'Gridにバインド
                Grid1.DataSource = dt
            End Using
        Catch ex As OracleException
            MessageBox.Show(ex.Message)

        End Try

    End Sub

切り捨て

文法
TRUNC ( number [, integer] )
数値 number を小数第 integer 位(省略時は 0)に切り捨てた値を戻す。
引数
number 切り捨てを行う数値(数値式)
integer 切り捨てする位 (デフォルト0)

使用例

select
trunc(123.4544,0),
trunc(123.4544,1),
trunc(123.4544,2),
trunc(123.4544,-1),
trunc(123.4544,-2)
from dual

結果
TRUNC関数

Imports Oracle.DataAccess.Client

Public Class frmSQL_Trim

    Private dt As DataTable = Nothing

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Try
            Using da As New OracleDataAdapter(TextSQL.Text.Trim, clsGlobal.gConnetionString)

                dt = New DataTable
                da.Fill(dt)

                'Gridにバインド
                Grid1.DataSource = dt
            End Using
        Catch ex As OracleException
            MessageBox.Show(ex.Message)

        End Try

    End Sub

切り上げ

直接切り上げする関数は見あたりません。TRUNCの応用で実現します

使用例

select
TRUNC(123.4544 + 0.9,0),
TRUNC(123.4544 + 0.09,1),
TRUNC(123.4544 + 0.009,2),
TRUNC(123.4544 + 9,-1)
from dual

結果
切り上げ

Imports Oracle.DataAccess.Client

Public Class frmSQL_Trim

    Private dt As DataTable = Nothing

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Try
            Using da As New OracleDataAdapter(TextSQL.Text.Trim, clsGlobal.gConnetionString)

                dt = New DataTable
                da.Fill(dt)

                'Gridにバインド
                Grid1.DataSource = dt
            End Using
        Catch ex As OracleException
            MessageBox.Show(ex.Message)

        End Try

    End Sub

履歴

Loading