Java - Insert double values in DB properly [duplicate] - java

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.

Related

Why use int instead of Integer (or the other way around) in Java? [duplicate]

This question already has answers here:
When to use wrapper class and primitive type
(11 answers)
What is the difference between Integer and int in Java?
(11 answers)
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
I know that Integer is a class and int is just a number, but when should we use one over another and how to convert Integer to int (and vice versa)?
** Also, there is this
question (what is autoboxing by the way) but I am asking WHEN to use int over Integer in actual programming (such as performance issues, ease of use and readability) and vice versa and not the DIFFERENCE between them.

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.

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

Round Off Error? - Java [duplicate]

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

Categories