arithmetic operation on float number

arithmetic operation on float number

hi here is my code

class divs { public static void main(String args[]) { double dub=14.2f,dou; int num; num=(int)dub; dou=dub-num; System.out.println(dou); } }

I convert Double Value DUB=14.2 into integer variable NUM . Now NUM Value is "14".When i make subtraction like(" dou=dub-num ") it will give output like "0.1999998092". but I want to show output like "0.20".why compiler give wrong output?

View Answers

December 6, 2012 at 10:53 AM

Floating-point numbers are imprecise, especially since they work in binary fractions (1/2, 1/4, 1/8, 1/16, 1/32, ...) instead of decimal fractions (1/10, 1/100, 1/1000, ...). Therefore it displays 0.1999998092 instead of 0.20.

Ads









Related Tutorials/Questions & Answers:
arithmetic operation on float number
arithmetic operation on float number  hi here is my code class divs { public static void main(String args[]) { double dub=14.2f,dou; int num; num=(int)dub; dou=dub-num
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........  code for a simple java program which performs basic arithmetic operation addition,subtraction
Advertisements
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface arith { int a=5; int b=8; void add(); void mul(); void sub(); void
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface arith { int a=5; int b=8; void add(); void mul(); void sub(); void
The Arithmetic Operators
to calculate arithmetic operation. The java programming tutorial provide operators... Java Example Using Arithmetic Operators  ... the arithmetic values. First of all, we have to define class named "
Arithmetic Operators
Arithmetic Operators Operator is used to perform operation on variable and values. Arithmetic Operators is used to perform arithmetic operations(like... the list of available arithmetic operators : OPERATOR WORK USE
string to float
string to float  hiii. how can i change my string value in float for some operation?? give me some code for this??   hello, if rate is your textfield then float FloPri = [rate.text floatValue]; the value
float validation for jTextField
float validation for jTextField  Hi; I try that users enter only float number into jtextfield but I can not handle it. I try regex in keylistener but I couldn't be successful. Can you help me please
ModuleNotFoundError: No module named 'arithmetic'
ModuleNotFoundError: No module named 'arithmetic'  Hi, My Python... 'arithmetic' How to remove the ModuleNotFoundError: No module named 'arithmetic' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'arithmetic'
ModuleNotFoundError: No module named 'arithmetic'  Hi, My Python... 'arithmetic' How to remove the ModuleNotFoundError: No module named 'arithmetic' error? Thanks   Hi, In your python environment you
Conversion from int to float
Conversion from int to float: In this tutorial we will learn how to convert an int type value  to float type. Description: This program will take two...; to float type data. The line int a = Integer.parseInt(buffreader.readLine
MySQL Arithmetic
MySQL Arithmetic This example illustrates how to use arithmetic operator in the MySQL. In this example we use arithmetic operator (+, /, -, *, %).   Query   Output  
Java - Arithmetic Operation, Conversion and Casts in java
Java - Arithmetic Operation, Conversion and Casts in java..., this will be illegal operation. For storing your calculated int value in a byte.... This type of operation has illustrated below : In this example we will see
The float Keyword
The float Keyword         The float is a Java keyword that may not be used as identifiers i.e.... single-precision floating-point number. It is also a java primitive data type
ModuleNotFoundError: No module named 'float'
ModuleNotFoundError: No module named 'float'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'float' How to remove the ModuleNotFoundError: No module named 'float'
ModuleNotFoundError: No module named 'float'
ModuleNotFoundError: No module named 'float'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'float' How to remove the ModuleNotFoundError: No module named 'float'
ModuleNotFoundError: No module named 'float'
ModuleNotFoundError: No module named 'float'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'float' How to remove the ModuleNotFoundError: No module named 'float'
why not float main?
why not float main?  why should the main be int or void?why cant it be float or char? why int main()?why not float main()?or char main
why not float main?
why not float main?  why should the main be int or void?why cant it be float or char? why int main()?why not float main()?or char main
ModuleNotFoundError: No module named 'arithmetic-bsr'
ModuleNotFoundError: No module named 'arithmetic-bsr'  Hi, My... named 'arithmetic-bsr' How to remove the ModuleNotFoundError: No module named 'arithmetic-bsr' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'arithmetic-calculator'
ModuleNotFoundError: No module named 'arithmetic-calculator'  Hi...: No module named 'arithmetic-calculator' How to remove the ModuleNotFoundError: No module named 'arithmetic-calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'arithmetic-pidouki'
ModuleNotFoundError: No module named 'arithmetic-pidouki'  Hi, My... named 'arithmetic-pidouki' How to remove the ModuleNotFoundError: No module named 'arithmetic-pidouki' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'arithmetic-bsr'
ModuleNotFoundError: No module named 'arithmetic-bsr'  Hi, My... named 'arithmetic-bsr' How to remove the ModuleNotFoundError: No module named 'arithmetic-bsr' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'arithmetic-calculator'
ModuleNotFoundError: No module named 'arithmetic-calculator'  Hi...: No module named 'arithmetic-calculator' How to remove the ModuleNotFoundError: No module named 'arithmetic-calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'arithmetic-cloudea'
ModuleNotFoundError: No module named 'arithmetic-cloudea'  Hi, My... named 'arithmetic-cloudea' How to remove the ModuleNotFoundError: No module named 'arithmetic-cloudea' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'arithmetic-graphing'
ModuleNotFoundError: No module named 'arithmetic-graphing'  Hi, My... named 'arithmetic-graphing' How to remove the ModuleNotFoundError: No module named 'arithmetic-graphing' error? Thanks   Hi
ModuleNotFoundError: No module named 'arithmetic-pidouki'
ModuleNotFoundError: No module named 'arithmetic-pidouki'  Hi, My... named 'arithmetic-pidouki' How to remove the ModuleNotFoundError: No module named 'arithmetic-pidouki' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'kcet-Arithmetic'
ModuleNotFoundError: No module named 'kcet-Arithmetic'  Hi, My... named 'kcet-Arithmetic' How to remove the ModuleNotFoundError: No module named 'kcet-Arithmetic' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Lit-Arithmetic'
ModuleNotFoundError: No module named 'Lit-Arithmetic'  Hi, My... named 'Lit-Arithmetic' How to remove the ModuleNotFoundError: No module named 'Lit-Arithmetic' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'lti-arithmetic'
ModuleNotFoundError: No module named 'lti-arithmetic'  Hi, My... named 'lti-arithmetic' How to remove the ModuleNotFoundError: No module named 'lti-arithmetic' error? Thanks   Hi, In your python
NSString to float conversion
NSString to float conversion  HI, I my iPhone and iPad application I have to convert NSString to float. Provide me example of NSString to float conversion. Thanks   Hi, Please see NSString to float conversion

Ads