Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Number randomly rounding

Hi, from a book I'm reading, I made a volume calculator using a foreign subroutine. The subroutine (TextIO) can be found by CLICKING HERE

The code for what I've made is as followed:

Code:
```
public class Volume {
public static void main(String[] argv) {
float squareLength;
float area;
float otherDimension;
float volume;

squareLength = TextIO.getlnInt();

area = (float)Math.pow(squareLength,2);
System.out.println(area);

otherDimension = TextIO.getlnInt();

volume = area * otherDimension;
System.out.print("The volume of this shape is: ");
System.out.println(volume);

}

}```

Basically, by using TextIO, this system works out the volume by squaring squareLength and then multiplying the area by the other dimension. The system works fine, apart from one problem: whenever you square a decimal number or multiply a decimal number by the area in this system, it randomly rounds the number either down despite the fact I'm using primitive type float.

I don't want it to change the number at all, I want the system to print the actual number for the area and the volume.

Thanks

• If you look @ the getlnInt() it returns an int

Code:
```public static int getlnInt() {
int x=getInt();
emptyBuffer();
return x;
}```
and then...
Code:
```getInt()     {
}```
so you are getting as your most primitive type as an Int which makes the float, not a float.

*I think

• Originally Posted by alykins
If you look @ the getlnInt() it returns an int

Code:
```public static int getlnInt() {
int x=getInt();
emptyBuffer();
return x;
}```
and then...
Code:
```getInt()     {
}```
so you are getting as your most primitive type as an Int which makes the float, not a float.

*I think
Thanks for pointing that out, all it involved was just changing the int in the getln subroutine to a float.

•