How can I intentionally create random floating point / decimal precision errors in java?

My goal is to generate random numbers that all have decimal precision errors. Here are some examples of types of numbers I would like to generate: 1.8181818723678589 1.2727272510528564 0….

‘OptionalDouble.getAsDouble()’ without ‘isPresent()’ check

I’ve seen a bunch of solutions for this question but no matter what I try, IDEA still reports an error. Consider the following block: double testDouble= customClass.stream() .mapToDouble(…

Game Of Life game: Check 2D array 8 closest surroundings; ArrayIndexOutOfBoundsException issue

I have encountered this problem and i couldn’t find the solution. There is a 2D array with only zeros and ones in it (the size of the array doesnt really matter, i worked with 10×10). Zero means dead …

How to implement Body Mass Index (BMI)in Java

My problem is how can I implement without the Scanner method and with Math.round and Math.pow? Here is my code: import java.util.Scanner; public class BMI{ public static void main(String …

Trying to sort a Double Collection

I am trying to sort a Collection. I cant seem to get my code to work with what I have found online. Collection: [104.131119, 104.188937, 93.174548, 100.533096, 97.902247, 98.608619, 93.380054, 106….

how do you round up a double user input value in java? [closed]

Im a student whos making a simple grading system and Im struggling on how to do this when I type in a specific number it go down to else bypassing my else-if statements the numbers are 98, 67, 98, 80 …

How come declaring something as a double data type would lead the ide to think it is a integer?

I am very confused on how a declared double data type would lead to the intellij ide to believe I was requiring a int to declare. Can someone give me some insight on this? Here is the code in a …

How likely is BigDecimal to cause memory issues for a POS program?

I understand that BigDecimal is the most accurate way to express currency because treating currency values as a floating-point data type tends to cause rounding errors. However, I also understand that …

Convert double to float in Java

I am facing an issue related to converting double to float. Actually, I store a float type, 23423424666767, in a database, but when we get data from the database in the below code, getInfoValueNumeric(…

is there anyway to convert from Double to BigInteger?

Is there anyway to convert from double value to BigInteger? double doubleValue = 64654679846513164.2; BigInteger bigInteger = (BigInteger) doubleValue; I try to cast it but it didn’t work.