| Author |
j2me: Unable to import java.math.*;
|
Sangeeta Vepa
Greenhorn
Joined: Sep 20, 2003
Posts: 22
|
|
Hi all, I am writing a midp midlet in which i want to ROUND a value so that i can use that value in the graphics to fill a rectangle. round(anyvalue) is available in java i suppose. But in am unable to import java.math.*. I am using "Sun One Studio Update 1" to write the code. Please help, is there any other way in which i can store a decimal value into a integer variable. Basically i want to strip off the decimal part from a value. The value is stored in a double variable. Another question: How can i print a double variable. System.out.println("This is a double value " + variable); doesn't work. What Should be the typecast? Thanks.
|
 |
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
|
|
Do note that not all J2SE packages are available on the J2ME platform. Furthermore, MIDP 1.0 for example doesn't support floating point numbers (float, double) at all!
|
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
|
 |
Sangeeta Vepa
Greenhorn
Joined: Sep 20, 2003
Posts: 22
|
|
Hi Lasse, I am grateful for this prompt reply. Let me specify what i want to do. But i really need to implement this as i m drawing a rectangle based graph in which i have to fill int values only, as fillRect takes only int values. Now its like an order entry form in which i take order values and show graphs for different clients. So for every client i calculate the "Total Order Value" which is sum of a number of order for that particular client. Now i pick up the largest "Total Order Value" for that set of clients. To show it in a graph, i m filling the rectangles with the value of their orders horizontally. But the total width of a mobile application takes only 180 ( i mean getwidth() returns 180) which throws the graph outside the emulator. To solve this problem i m dividing each client's "Total Order Value" from the "Largest Order Value" and take percentage so that i can show the relative difference in the graph. THATS WHAT THE PROBLEM IS : WHEN I DIVIDE THERE'S NOTHING THROUGH WHICH I CAN TAKE A PERCENTAGE AND "ROUND" IT OFF. THEN CONVERT THE DOUBLE VALUE TO "INTEGER" AND PUT IT IN drawRect(int,int,int,int). How can i implement this in any other way. Thanks Sangeeta
|
 |
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
|
|
I see the following options: 1) Just do "int x = 5 / 2;" and be happy with what you get (x = 2). 2) Use a special-purpose floating-point API for J2ME such as MathFP or SpruceFloat 3) Write your own fixed point arithmetics floating point math library
|
 |
 |
|
|
subject: j2me: Unable to import java.math.*;
|
|
|