Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Number randomly rounding

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 06-21-2012, 08:11 PM PM User | #1 Jemdt New Coder   Join Date: May 2012 Posts: 29 Thanks: 2 Thanked 0 Times in 0 Posts 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; TextIO.put("Please enter the length of your square cuboid face: "); squareLength = TextIO.getlnInt(); area = (float)Math.pow(squareLength,2); System.out.print("Your area is: "); System.out.println(area); TextIO.put("Please enter the length of your other dimension: "); 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
 06-21-2012, 09:57 PM PM User | #2 alykins Senior Coder     Join Date: Apr 2011 Posts: 1,608 Thanks: 37 Thanked 183 Times in 182 Posts If you look @ the getlnInt() it returns an int Code: ```public static int getlnInt() { int x=getInt(); emptyBuffer(); return x; }``` and then... Code: ```getInt() { return (int)readInteger(Integer.MIN_VALUE, Integer.MAX_VALUE); }``` so you are getting as your most primitive type as an Int which makes the float, not a float. *I think __________________ I code C hash-tag .Net Reference: W3C W3CWiki .Net Lib Validate: html CSS Debug: Chrome FireFox IE
06-22-2012, 08:43 PM   PM User | #3
Jemdt
New Coder

Join Date: May 2012
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Quote:
 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() { return (int)readInteger(Integer.MIN_VALUE, Integer.MAX_VALUE); }``` 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.

 Bookmarks

 Tags round help java print

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 12:11 PM.