Round Off Error? - Java [duplicate] - java

This question already has answers here:
Is floating point math broken?
(31 answers)
Floating point multiplication in java [duplicate]
(3 answers)
Closed 8 years ago.
Ok, so i made a scientific calculator recently and one of my friends was using it when he said that if he types in (2.1 * 3) the answer should be 6.3 but he recieves something like: 6.30000001.
Why does this happen?
Is this some sort of bug in java?
EDIT: Its not just a problem with my calc, i also made a small java file for multiplying 2 numbers and i face the same probelem even in cmd

Related

How to set sth. on infinity in Java? [duplicate]

This question already has answers here:
How to implement infinity in Java?
(11 answers)
Closed 5 years ago.
I want to implement the dijkstra algorithm and have to set each note at the beginning to infinity.
I would like to know, if there is any function in Java which makes it easy.
Double.POSITIVE_INFINITY if you are using Double to store your data.
Also note that this is not a number, which is nice depending on what you want to do. Double supports this concept.

how to store "12000000000" or a 11 digit number in java [duplicate]

This question already has answers here:
Large Numbers in Java
(6 answers)
Closed 6 years ago.
given here only as a form of validating.Which data type to use to store such a big number
Probably what you're looking for is BigInteger, BigDecimal if you want decimals instead.

Java - Insert double values in DB properly [duplicate]

This question already has answers here:
Is floating point math broken?
(31 answers)
Closed 6 years ago.
I'm using H2 Database and when double and float values inserted into my H2 DB, the loss of precision is occurred and, for example, 1.7999999523162842 displayed instead of 1.8.
Declaring variable type as BigDecimal instead Double or Float solved issue.

why 0.3+0.3+0.3 = 0.899999999999999 in java? [duplicate]

This question already has answers here:
How to avoid floating point precision errors with floats or doubles in Java?
(12 answers)
Closed 8 years ago.
In my Java class.
My teacher has asked this question.
Can anyone help me out, I would appreciate it. TY.
why
0.3+0.3+0.3 = 0.899999999999999
in java ?????
Its because of floating point precision errors. The reason is that these data types are built for fast and accurate approximations and not for exact results. For that we use BigDecimal
For more info
Java Types
Java Float Types

How to calculate mean, median and mode from a set of CONTINUOUS numbers in Java? [duplicate]

This question already has answers here:
Mean, Median, Mode, Range - Java [closed]
(2 answers)
Closed 8 years ago.
Do you know if there is a library that supports these statistical operations or a way to do it in java?
There are no library methods in java to achieve this. Please read this similar topic
Mean, Median, Mode, Range - Java

Categories