(Sumber: milist DOTNET) pembulatan angka

Jawab (Sumber: milist DOTNET) pembulatan angka

  • Friday, January 27, 2012 6:40 PM
    Moderator
     
     

    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

    jadi mau di bulatkan ke bawah jadi 125.500 dan ke atas jadi 125.600


    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.

All Replies

  • Friday, January 27, 2012 6:41 PM
    Moderator
     
      Has Code
    Public Shared Function SomeFunc(ByVal value As DoubleAs 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:43 PM
    Moderator
     
     Answered

    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, February 24, 2012 3:29 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 5:29 PM
     
     
    Mohon dibuat lebih spesifik dong pertanyaannya. Biar saya mudah menangkapnya.
  • Wednesday, March 07, 2012 10:58 AM
     
     

    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)
                    ListBox1.Items.Add(x)
                    ListBox2.Items.Add(y)
                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..!!

  • Thursday, March 08, 2012 8:21 AM
     
     Proposed Answer

    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 Wahyu VB .Net Thursday, March 08, 2012 8:21 AM
    •