منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : Math function to round up the values to .0 or .5
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
How can I round numbers up to the nearest whole or to the nearest half?

For Example:

كود :
> 23.15 --> 23.5
> 23.56 --> 24.0
اتمنى أن يفى هذا بالغرض
Heart
[attachment=28215]
Take it's :
كود :
   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Me.Text = Approximation(TextBox1.Text)
   End Sub

   Function Approximation(Number As Double) As String
       Dim N1() As String = Format(Double.Parse(Number), "0.00").Split(".")
       If Val(N1(1)) > 50 Then
           N1(1) = "00"
           N1(0) = N1(0) + 1
       ElseIf Val(N1(1)) > 0 Then
           N1(1) = 50
       End If

       Return N1(0) & "." & N1(1)
   End Function
(18-09-22, 01:35 AM)رمضان272 كتب : [ -> ]اتمنى أن يفى هذا بالغرض
Heart

Thank you very much

(18-09-22, 01:41 AM)Taha Okla كتب : [ -> ]Take it's :
كود :
   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Me.Text = Approximation(TextBox1.Text)
   End Sub

   Function Approximation(Number As Double) As String
       Dim N1() As String = Format(Double.Parse(Number), "0.00").Split(".")
       If Val(N1(1)) > 50 Then
           N1(1) = "00"
           N1(0) = N1(0) + 1
       ElseIf Val(N1(1)) > 0 Then
           N1(1) = 50
       End If

       Return N1(0) & "." & N1(1)
   End Function
Thank you very much