Results 1 to 4 of 4
Thread: Rounding decimal error
- 06-01-2011, 12:45 AM #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);
}
}
- 06-01-2011, 12:57 AM #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);
- 06-01-2011, 01:00 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
*facepalm* DUH ...thanks I guess I'm just temporarily brain dead :/
- 06-01-2011, 01:07 AM #4
Similar Threads
-
Compile Error (decimal rounding attempt)
By mylosol in forum New To JavaReplies: 2Last Post: 05-08-2011, 11:13 PM -
Got an error when enter the number in decimal eg 30.23
By Neera in forum New To JavaReplies: 3Last Post: 01-01-2011, 02:36 AM -
Decimal to binary, octal to decimal
By matejm1994 in forum New To JavaReplies: 3Last Post: 12-26-2010, 09:59 AM -
rounding double to two decimal places
By javaMike in forum Advanced JavaReplies: 15Last Post: 03-10-2010, 12:04 AM -
java division and decimal error
By heartysnowy in forum New To JavaReplies: 5Last Post: 10-07-2009, 04:57 PM
Bookmarks