Thread: Rounding decimal error

1. Member Join Date
Jan 2011
Posts
11
Rep Power
0 Rounding decimal error

I am trying to round these decimals, but I get the error unexpected type: found: value required: variable. (First of all I don't know how you can round a variable, but that's not the point) I just want to round, this shouldn't be rocket science and I probably made some stupid mistake, but I would really appreciate it if someone pointed me in the right direction, and by the right direction I mean directly tell me what I'm doing wrong. Arigato gozaimasu (thank you) in advance.
import java.io.*;
import java.util.*;
import java.util.Random.*;
public class HA2
{
public static void main(String[] args)
{

//let R be any real rational number
//if 0=0 infinite solutions if 0=anything else no solution
//first problem will be Infinite or No Solutions with Elimination
Random generator=new Random();//use nextGaussian() to create random positive and negative ints
double R1=(generator.nextGaussian()*100);//makes a random real number
double R2=generator.nextGaussian();
double R3=generator.nextGaussian();
double R4=generator.nextGaussian();
double R5=generator.nextGaussian();
double R6=generator.nextGaussian();
Math.round((R1*100)/100)=R1;//this is where error occurs
Math.round(100*R2)/(100)=R2;
Math.round(100*R3)/(100)=R3;
Math.round(100*R4)/(100)=R4;
Math.round(100*R5)/(100)=R5;
Math.round(100*R6)/(100)=R6
;

System.out.println("Use elimination to determine whether this will have infinite or no solutions\n " +R1+"x+"+R2+"y="+R3+"\n" +R4+"x+"+R5+"y="+R6);

}
}  Reply With Quote

2. The problem is your trying to assign a value to a method. When you type "Math.round(100*R2)/(100)=R2;" Java thinks your trying to set Math.round() (which is a method) to the double value of R2 and you can't do this because methods don't hold values. This is what causes the error you are getting. Try this instead. Also code blocks make your code easier to read :)
Java Code:
R1 = Math.round((R1*100)/100);
R2 = Math.round(100*R2)/(100);
R3 = Math.round(100*R3)/(100);
R4 = Math.round(100*R4)/(100);
R5 = Math.round(100*R5)/(100);
R6 = Math.round(100*R6)/(100);  Reply With Quote

3. Member Join Date
Jan 2011
Posts
11
Rep Power
0 *facepalm* DUH ...thanks I guess I'm just temporarily brain dead :/  Reply With Quote

4. No problem. Everyone has brain farts, and it really doesn't help that some of Java's error messages can be somewhat cryptic.  Reply With Quote Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•