Results 1 to 7 of 7
Thread: strange outcome!
- 08-20-2010, 07:34 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 4
- Rep Power
- 0
strange outcome!
public class Test {
public static void main(String[] args) {
double n = 20.5 - 20.37;
System.out.println("n = " + n);
}
}
With this code the outcome should be n = 0.13 but instead, it displays 0.129999999999999
I don't know what wrong with this code.
Could anyone explain me what happen?
Thank you ^^
- 08-20-2010, 08:20 AM #2
- 08-20-2010, 08:39 AM #3
Member
- Join Date
- Aug 2010
- Posts
- 4
- Rep Power
- 0
Thank you for reply
I've just studied programming language and I have chosen Java as primary language. So I don't know much about programming. Could you show me coding that make this outcome as 0.13?
Thank you.
- 08-20-2010, 08:52 AM #4
Have a look at the DecimalFormat API.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 08-20-2010, 09:22 AM #5
Member
- Join Date
- Aug 2010
- Posts
- 4
- Rep Power
- 0
import java.text.*;
public class Test {
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("0.00");
double n = 20.5 - 20.37;
System.out.println(df.format(n));
}
}
- 08-20-2010, 09:25 AM #6
Member
- Join Date
- Aug 2010
- Posts
- 4
- Rep Power
- 0
Thank for your recommendation
^^
- 08-20-2010, 09:36 AM #7
You're welcome.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
strange problem
By dinosoep in forum New To JavaReplies: 6Last Post: 05-01-2010, 10:28 AM -
Strange Error
By AJArmstron@aol.com in forum New To JavaReplies: 1Last Post: 04-18-2010, 09:31 PM -
Strange Problem
By Aseem in forum JDBCReplies: 5Last Post: 02-12-2010, 07:46 AM -
strange swt exception
By ahmed.kotb in forum SWT / JFaceReplies: 0Last Post: 04-23-2009, 10:15 AM -
Outcome differ from Netbeans and Java Web Start
By bongia in forum New To JavaReplies: 1Last Post: 11-06-2007, 01:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks