On my Pixel 7 device, I want to know how many density-independent pixels (dp) I have. So, I use this formula:
displayMetrics.widthPixels / displayMetrics.density
However, I have an issue because displayMetrics.widthPixels = 1080
(which is okay) and displayMetrics.density = 2.625
. When I calculate 1080 / 2.625, it equals 411.428571 density-independent pixels, which is not an integer. It seems that displayMetrics.density = 2.625 may be incorrect because it's unusual to have a fraction of a density-independent pixel.
How can I obtain the correct value for displayMetrics.density? I suppose it's 2.62135922, which would result in 412 density-independent pixels, making it seem more visually appealing.