Bael 7146 improvement to this article convert double to float in java (#15067)

* Commit 1 - Anton Dalagan Code for Evaluation article. Contains Unit tests, domain class, and App main method.

* BAEL-7146 Updated the unit test to display the results of the conversion. This will be explained in the article itself.

* BAEL-7146 cleaned up pR
This commit is contained in:
Anton Dalagan 2023-10-27 18:44:07 +02:00 committed by GitHub
parent 520b679733
commit 3c8d10dd82
1 changed files with 11 additions and 7 deletions

View File

@ -7,23 +7,27 @@ public class FloatDoubleConversionsTest {
@Test
public void whenDoubleType_thenFloatTypeSuccess(){
double interestRatesYearly = 13.333333333333334;
double interestRatesYearly = 13.333333333333333;
float interest = (float) interestRatesYearly;
Assert.assertEquals(13.333333f, interest, 0.000004f);
System.out.println(interest); //13.333333
Assert.assertEquals(13.333333f, interest, 0.000001f);
Double monthlyRates = 2.111111111111112;
Double monthlyRates = 2.111111111111111;
float rates = monthlyRates.floatValue();
Assert.assertEquals(2.1111112f, rates, 0.00000013);
System.out.println(rates); //2.1111112
Assert.assertEquals(2.1111111f, rates, 0.0000001f);
}
@Test
public void whenFloatType_thenDoubleTypeSuccess(){
float gradeAverage =2.05f;
double average = gradeAverage;
Assert.assertEquals(2.05, average, 0.06);
System.out.println(average); //2.049999952316284
Assert.assertEquals(2.05, average, 0.01);
Float monthlyRates = 2.1111112f;
Float monthlyRates = 2.1111111f;
Double rates = monthlyRates.doubleValue();
Assert.assertEquals(2.11111112, rates, 0.0000002);//true
System.out.println(rates); //2.1111111640930176
Assert.assertEquals(2.11111111, rates, 0.0000001);//true
}
}