Merge remote-tracking branch 'upstream/master'
This commit is contained in:
+15
@@ -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);
|
||||
}
|
||||
}
|
||||
+33
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user