Bael 6962 convert double to float in java (#14883)

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

* BAEL-6962 - Created unit test, and updated pom.xml

* BAEL-6962 - Removed files unrelated to the article

* BAEL-6962 - Added a declartions for float and double in diff class. Updated unit tests.
This commit is contained in:
Anton Dalagan 2023-09-30 17:39:12 +02:00 committed by GitHub
parent b63f63c7da
commit 306f1335b8
3 changed files with 60 additions and 0 deletions

View File

@ -18,6 +18,18 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,15 @@
package com.baeldung.floatdoubleconversions;
public class FloatAndDoubleConversions {
public static void main(String args[]){
float vatRate = 14.432511f;
System.out.println("vatRate:"+vatRate);
Float localTaxRate = 20.12434f;
System.out.println("localTaxRate:"+localTaxRate);
double shootingAverage = 56.00000000000001;
System.out.println("shootingAverage:"+shootingAverage);
Double assistAverage = 81.123000000045;
System.out.println("assistAverage:"+assistAverage);
}
}

View File

@ -0,0 +1,33 @@
package com.baeldung.floatdoubleconversions;
import org.junit.Assert;
import org.junit.Test;
public class FloatDoubleConversionsTest {
@Test
public void whenDoubleType_thenFloatTypeSuccess(){
double interestRatesYearly = 13.333333333333334;
float interest = (float) interestRatesYearly;
System.out.println(interest); //13.333333
Assert.assertTrue(Float.class.isInstance(interest));//true
Double monthlyRates = 2.111111111111112;
float rates = monthlyRates.floatValue();
System.out.println(rates); //2.1111112
Assert.assertTrue(Float.class.isInstance(rates));//true
}
@Test
public void whenFloatType_thenDoubleTypeSuccess(){
float gradeAverage =2.05f;
double average = gradeAverage;
System.out.println(average); //2.049999952316284
Assert.assertTrue(Double.class.isInstance(average));//true
Float monthlyRates = 2.1111112f;
Double rates = monthlyRates.doubleValue();
System.out.println(rates); //2.1111112
Assert.assertTrue(Double.class.isInstance(rates));//true
}
}