04-07-2009 03:55 PM
Hi,
Do we have equivalent methods in J2ME for Math.round() and Math.random()? I could not find it either in Java.util.Math or net.rim.device.api.Math
Thanks.
Reshma
Solved! Go to Solution.
04-07-2009 04:19 PM
Don;t know of a round function. For random, see Random class.
04-07-2009 04:49 PM - last edited on 04-07-2009 04:50 PM
04-09-2009 12:47 AM - last edited on 04-09-2009 12:52 AM
Thanks for your response.
I am trying to round a float but I did NOT find a method in MathUtilities to round a float. I found that MathUtilities.round(float) was a new method added in JDE 4.6. I am using JDE 4.2.1. Is there any other way ?
04-09-2009 12:52 AM
04-09-2009 01:27 AM - last edited on 04-09-2009 01:28 AM
@ JavaMEUser, You can write your own Math class for your application, use the following code..
public static int round(float f)
{
return (int)(f + 0.5F);
}
public static long round(double d)
{
return (long)(d + 0.5D);
}
04-09-2009 01:27 AM
I have a library of fast math functions I was creating and these are the existing libs I found with math functions in 4.7. There are quite a bit....
* java.lang Has a bunch of types like Float, etc, that have some useful functions.
* java.lang.Math Normal Java math functions. This is lacking some.
* net.rim.device.api.util.MathUtilities Missing Math functions in double precision.
* net.rim.device.api.math Blackberry math (The ones below are part of that)
* Fixed32 16.16 fixed point math
* VecMath Uses Fixed32 to transform graphics.
* java.util Has Random and a few other useful ones.
I've used Fixed32 and VecMath a lot for polygon manipulation.
Round exists from double precision to long (64-bit integer) in MathUtilities.
Random exists under java.util
Whenever you need a function or class, go to the javadocs, select all classes, then at the top, click on Index, wait for it to load completely. Then click on the letter that your function starts with (like R for random). Then scroll down until you find it. Usually works quite well.
Enjoy
-D
===============
Donald Murray
CTO IPPUB LLC
"If this solves your problem, click on Solved and Kudos for the person who helped you"