Results 1 to 4 of 4
Thread: Truncate out
- 05-15-2012, 09:00 PM #1
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
Truncate out
hi,
I wrote a small program to compute BMI, but is there a way to truncate the output of this?
on the output i get Your BMI is 26.854599999999998. How can i make it so i get like 26.8573?XML Code:import java.util.Scanner; public class ComputeBMI { public static void main(String[] arg) { //Create an instance of the Scanner Scanner input = new Scanner(System.in); //Input System.out.print("Enter weight in Pounds: "); double Weight = input.nextDouble(); System.out.print("Enter height in inches: "); double Height = input.nextDouble(); //Math and variables double BMI = (Weight / (Height * Height)) * 703; //Display Result System.out.println("Your BMI is " + BMI); } }
- 05-15-2012, 09:05 PM #2
Re: Truncate out
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-15-2012, 09:07 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 59
- Rep Power
- 0
Re: Truncate out
Information on how to use the Formatter class can be found here:Java Code:formatter.format(Locale.FRANCE, "e = %+10.4f", Math.E);
Formatter (Java 2 Platform SE 5.0)
- 05-16-2012, 06:12 AM #4
Re: Truncate out
1. Don't spoonfeed. Especially not bad code.
2. Don't post links to old EOL Java API. bookmark these:
Java Platform SE 6
Java Platform SE 7
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
I need to truncate a file with 10 or more lines, to 10, removing the first lines
By sledjama in forum New To JavaReplies: 3Last Post: 10-25-2011, 06:29 PM -
JList item text does not truncate when it's HTML
By edsporty in forum New To JavaReplies: 1Last Post: 03-02-2011, 08:09 PM -
truncate a decimal number ?
By hacikho in forum New To JavaReplies: 5Last Post: 10-13-2010, 08:58 PM -
To truncate jump of line in jsp
By Eric in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 06-09-2007, 03:58 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks