Sum of two floats with 2 decimal places resulting in 4 decimal places in JAVA

Asked

Viewed 303 times

1

I am having a JAVA problem where I want to store calculation results with only 2 decimal places in SQL Server. For that at the end of my calculations I perform:

Math.round(valor * 100.0f) / 100.0f;

to obtain the value to two decimal places. After entering the values in the bank I am consulting them and are really only stored with 2 decimal places.

When do I requisition SELECT they are coming with 2 decimal places too.

But the weird thing happens when I try add up two of these values, the result of this sum gives a number with 4 decimal places, follows debug picture:

Resultado inesperado

What could be going on? This rounding is right?

--

In addition to making the requisition of INSERT (just to make sure that the value will be entered to 2 decimal places):

INSERT INTO tableX (valor) values (ROUND(?,2))

However it continues to result in a number of 4 decimal places after the sum.

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.