The Artima Developer Community
Sponsored Link

Java Answers Forum
working with decimal point numbers

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
raam medaramitla

Posts: 2
Nickname: mpraam
Registered: Dec, 2013

working with decimal point numbers Posted: Dec 10, 2013 1:05 AM
Reply to this message Reply
Advertisement
Hello Artima;
Good Morning

Here I come up with a code that donot produce an accurate result
// my program goes like this


public class FloatingNumber {

public static void main(String...args) {

double i;
double num=0.0;
for(i=0.0;i<10;i++)
num=num+0.1;

System.out.println(num);

}

}
// output: 0.9999999999999999

the same code writen in C produced an Accurate result
// the C program goes like this

#include<stdio.h>
#include<math.h>

main()

{
double i, num=0.0;

for(i=0;i<10;i++)
num=num+0.1;
printf("%f",num);

}
// output: 1.0000

/** please explain me the difference and suggest me a bettrcode to obtain an accurate result through Java
Thanks in advance.

Topic: servlet Previous Topic   Next Topic Topic: Interesting Palindrome problem


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us