Merge pull request #8283 from sreekanthsnair/master
Double to Integer Casting (BAEL-3517)
This commit is contained in:
		
						commit
						369e95b8ca
					
				
							
								
								
									
										28
									
								
								java-numbers-3/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								java-numbers-3/pom.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||
|     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
|     <artifactId>java-numbers-3</artifactId> | ||||
|     <version>0.0.1-SNAPSHOT</version> | ||||
|     <name>java-numbers-3</name> | ||||
|     <packaging>jar</packaging> | ||||
| 
 | ||||
|     <parent> | ||||
|         <groupId>com.baeldung</groupId> | ||||
|         <artifactId>parent-java</artifactId> | ||||
|         <version>0.0.1-SNAPSHOT</version> | ||||
|         <relativePath>../parent-java</relativePath> | ||||
|     </parent> | ||||
| 
 | ||||
|     | ||||
|     <build> | ||||
|         <finalName>java-numbers-3</finalName> | ||||
|         <resources> | ||||
|             <resource> | ||||
|                 <directory>src/main/resources</directory> | ||||
|                 <filtering>true</filtering> | ||||
|             </resource> | ||||
|         </resources> | ||||
|     </build> | ||||
| 
 | ||||
| </project> | ||||
| @ -0,0 +1,36 @@ | ||||
| package com.baeldung.doubletolong; | ||||
| 
 | ||||
| import org.junit.Assert; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class DoubleToLongUnitTest { | ||||
| 
 | ||||
|     final static double VALUE = 9999.999; | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenDoubleValue_whenLongValueCalled_thenLongValueReturned() { | ||||
|         Assert.assertEquals(9999L, Double.valueOf(VALUE) | ||||
|             .longValue()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenDoubleValue_whenMathRoundUseds_thenLongValueReturned() { | ||||
|         Assert.assertEquals(10000L, Math.round(VALUE)); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenDoubleValue_whenMathCeilUsed_thenLongValueReturned() { | ||||
|         Assert.assertEquals(10000L, Math.ceil(VALUE), 0); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenDoubleValue_whenMathFloorUsed_thenLongValueReturned() { | ||||
|         Assert.assertEquals(9999L, Math.floor(VALUE), 0); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenDoubleValue_whenTypeCasted_thenLongValueReturned() { | ||||
|         Assert.assertEquals(9999L, (long) VALUE); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user