Author | Message |
---|---|
alope415
Posts: 12
|
Posted 16:12 Sep 23, 2016 |
I have a problem rounding certain numbers. Let me illustrate with an example: double area = [some area formula];
double answer = Math.round(area * 100) / 100.0;
Suppose I have an area that I need to round off to 2 decimal places. If area is, let's say, 123.14329, then the rounding formula should round it to: 123.14 (which would be my answer). But as I was doing my homework, I got a big answer like this: 4.00000496929807E14 If I use the rounding formula, it does not seem to do anything. I even displayed the answer and rounded answer at the same time and they are literally the same.
So how would I have to round a number if it is outputed as an exponent? |
icerrat
Posts: 1
|
Posted 16:45 Sep 23, 2016 |
Make sure you are using the correct values for the formula. If you are using math.sin or math.cos remember that it returns values in radians. You might need to convert from radians to degrees or vice versa. |
alope415
Posts: 12
|
Posted 18:38 Sep 23, 2016 |
Even with the correct values, I still get an exponent that doesn't seem to be rounded. But thanks for the degree/radian conversion. I honestly forgot about that. |
TonyOs1
Posts: 13
|
Posted 20:50 Sep 23, 2016 |
My best guess is that it may be a logic error in the area formula.. Hope this helps. |
cgome106
Posts: 19
|
Posted 09:09 Sep 28, 2016 |
You have the right steps, but you are doing them in the wrong order. My advice is to not divide in the same variable you are using to round. Instead, make two variables and do one step at a time |