r/java • • Mar 01 '22

Interview with Senior Java Developer

https://www.youtube.com/watch?v=kdMG40wUCm4
205 Upvotes

36 comments sorted by

View all comments

Show parent comments

12

u/VincentxH Mar 02 '22

BigDecimal is a datatype often used when accurate decimal arithmetic needs to be performed, like with money.

Using floating point primitives, like double, is a classic mistake. Because it leads to problems of floating point arithmetic inaccuracies.

It's both a standard interview question and common mistake in the wild.

0

u/[deleted] Mar 02 '22

[deleted]

6

u/temculpaeu Mar 02 '22

int cents only works if you dont have to deal with fractions of cents, not very common but it can happen

5

u/thisisjustascreename Mar 02 '22

Financial securities are very often denominated in fractions of a penny. There are also other currencies than dollars in the world.