Question : Convert a VB.NET function to java

Hi!

I am developing a java applet in netbeens.
But have problems to convert this function from
vb.net to java.

Please sombody help me convert this function to java.

Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Public Function RoundUp(ByVal num As Double) As Integer
        Try
            'Temp variable to hold the decimal portion of the parameter
            Dim temp As Double
            'Get the decimal portion
            temp = num - Math.Truncate(num)
            'If there is a decimal portion then we add 1 to force it to round up
            num = IIf(temp > 0, num + 1, num)
            'return the truncated version of the double which should be the number rounded up
            Return Math.Truncate(num)
        Catch ex As Exception
            MessageBox.Show("Error occured in: " & ex.StackTrace & vbCrLf & vbCrLf & "Error: " & ex.Message, _
                "Error.", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return Nothing
        End Try
    End Function

Answer : Convert a VB.NET function to java

double d1 = 123.456;

int roundedUp = (int) Math.ceiling(d);

sets 'roundedUp' to 124;

There is similar functionality in Math.floor(double d).



double d2 = -123.456

where
 ((int) Math.floor(d2)) == -124
and
 ((int) Math.ceiling(d2))  == -123

For further information, consult the JavaDOcs:
http://java.sun.com/javase/6/docs/api/java/lang/Math.html
Random Solutions  
 
programming4us programming4us