# (Sumber: milist DOTNET) pembulatan angka

### Question

• salam,

untuk pembulatan nilai angka ke atas dan ke bawah functionnya di vb.net apa ya? ada yang tau :D
misalnya nominal nya : 125.533

Agnes Sannie [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Friday, January 27, 2012 6:40 PM

• Pembulatan kebawah pakai Floor, keatas paka Ceiling. Contoh nominal 125533,
#kebawah -> Math.Floor(125533/100.0)*100
#keatas -> Math.Ceiling(125533/100.0)*100

Kalau titik pada contoh angka anda adalah tanda desimal (bukan pemisah ribuan), caranya sedikit beda

#kebawah -> Math.Floor(125.533*10.0)/10
#keatas -> Math.Ceiling(125.533*10.0)/10

Dijawab oleh: Putu Susila

Agnes Sannie [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Friday, January 27, 2012 6:43 PM

### All replies

• `Public Shared Function SomeFunc(ByVal value As Double) As Double`
`        If ((value - Math.Truncate(value)) < 0.5) Then`
`            Return (value - (value - Math.Truncate(value)))`
`        End If`
`        If ((value - Math.Truncate(value)) > 0.6) Then`
`            Return ((value - (value - Math.Truncate(value))) + 1)`
`        End If`
`        Return value 'Utak-atik disini`
```    End Function

```
```

```
`        Console.WriteLine(Class1.someFunc(3.44)) 'output 3`
`        Console.WriteLine(Class1.someFunc(3.55)) 'output 3.55`
`        Console.WriteLine(Class1.someFunc(3.66)) 'output 4`

Dijawab oleh: Agus Syahputra

Agnes Sannie [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Friday, January 27, 2012 6:41 PM
• Pembulatan kebawah pakai Floor, keatas paka Ceiling. Contoh nominal 125533,
#kebawah -> Math.Floor(125533/100.0)*100
#keatas -> Math.Ceiling(125533/100.0)*100

Kalau titik pada contoh angka anda adalah tanda desimal (bukan pemisah ribuan), caranya sedikit beda

#kebawah -> Math.Floor(125.533*10.0)/10
#keatas -> Math.Ceiling(125.533*10.0)/10

Dijawab oleh: Putu Susila

Agnes Sannie [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Friday, January 27, 2012 6:43 PM
• Kalau anda ingin angkanya benar-benar dibulatkan kebawah, semisal 9,9 tetap dibaca 9. Maka gunakan perintah fix(). Anda bisa cari artikel tersebut di MSDN kok.
Friday, February 24, 2012 3:29 PM
• Mohon dibuat lebih spesifik dong pertanyaannya. Biar saya mudah menangkapnya.
Friday, February 24, 2012 5:29 PM
• Permsi Mod..!!

Mau tanya...

Masih agak bingung nih..

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim a, b, x, y As Double
Dim i As Integer
a = TextBox1.Text
b = TextBox2.Text
x = a
y = b
For i = 1 To Val(Label8.Text)
x = x + Val(Label10.Text)
y = y + Val(Label11.Text)
Next

Nah script diatas nantinya akan menampilkan perulangan di ListBox..

trz.. bagaimana caranya biar pembulatan doublenya mnjadi 1 angka dibelakang koma

misalnya : angkanya 3,387383979634 menjadi 3,4 saja.

Klao bisa.. cepat yah mod..!! Tugas Kumpul Besok..!!

Terima Kasih..!!

Wednesday, March 07, 2012 10:58 AM
• Udah pernah pakai Format belum? Cara nulisnya seperti ini:

Dim a As Double = textbox1.text

Dim b as Double = Format(a,'#.#')

Kalo gak jelas juga, cari di msdn dengan kata kunci format. Contoh penggunaannya banyak banget kok. Semoga membantu.

• Proposed as answer by Thursday, March 08, 2012 8:21 AM
Thursday, March 08, 2012 8:21 AM