Using java 11 and Intellij Idea.
I'm in the situation where I get a string of data from an external system and need to reformat this. In the current setup I have this line to extract the value for a sales price:
BigDecimal sellingPrice = BigDecimal.valueOf(Double.parseDouble(somesalesprice));
According to the debugger, the output value of sellingPrice = "4.350000000" Now when I convert this according to this line of code:
long roundedSellingPrice = (long) (sellingPrice.doubleValue() * 100);
the result turns out to be "434". As can be seen, 1 (cent) has magically disappeared. I double-checked the values and this consistent. Out of the 500+ dataset that I'm working with, approx. 40 other records seem to have this problem. For the majority it seems to be going just fine.
I cannot find anything common between these records.
Also, it turns out, the result is always rounded down by 1 cent, never up.
Wonder what this could be?