Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
org.apache.commons.lang3.math.Fraction Example
What is org.apache.commons.lang3.math.Fraction class? How to use org.apache.commons.lang3.math.Fraction class?
✍: FYIcenter.com
org.apache.commons.lang3.math.Fraction class is a Java class
offered in commons-lang3.jar that
is a Number implementation of fractions.
Here is a simple example of org.apache.commons.lang3.math.Fraction class:
// Copyright (c) 2016 FYIcenter.com
import org.apache.commons.lang3.math.Fraction;
// Example of using the Fraction class
public class FractionExample {
public static void main(String[] args) throws Exception {
// Create a Fraction
Fraction a = Fraction.getFraction(1,3);
Fraction b = Fraction.getFraction(2,3);
// Perform fraction addition
Fraction x = a.add(b);
System.out.println("1/3 + 2/3: "+x.doubleValue());
// Perform fraction multiplication
x = a.multiplyBy(b);
System.out.println("1/3 * 2/3: "+x.doubleValue());
// Perform fraction division
x = a.divideBy(b);
System.out.println("(1/3)/(2/3): "+x.doubleValue());
}
}
You can compile and run the above example in a command window as shown below:
C:\fyicenter>\local\jdk-1.8.0\bin\javac -cp C:\local\commons-lang3-3.5\commons-lang3-3.5.jar FractionExample.java C:\fyicenter>\local\jdk-1.8.0\bin\java -cp .;C:\local\commons-lang3-3.5\commons-lang3-3.5.jar FractionExample 1/3 + 2/3: 1.0 1/3 * 2/3: 0.2222222222222222 (1/3)/(2/3): 0.5
⇒ FAQ for Apache commons-lang.jar
⇐ org.apache.commons.lang3.time.StopWatch Example
2016-11-22, ∼2389🔥, 0💬
Popular Posts:
JDK 11 java.smartcardio.jmod is the JMOD file for JDK 11 Smartcardio module. JDK 11 Smart Card IO mo...
What Is fop.jar? I got it from the fop-2.7-bin.zip. fop.jar in fop-2.7-bin.zip is the JAR file for F...
JDK 8 tools.jar is the JAR file for JDK 8 tools. It contains Java classes to support different JDK t...
What Is poi-examples-5.2.3.jar? poi-examples-5.2.3.jar is one of the JAR files for Apache POI 5.2.3,...
Java Advanced Imaging (JAI) is a Java platform extension API that provides a set of object-oriented ...