Categories:

Audio (13)

Biotech (29)

Bytecode (35)

Database (77)

Framework (7)

Game (7)

General (508)

Graphics (53)

I/O (32)

IDE (2)

JAR Tools (86)

JavaBeans (16)

JDBC (89)

JDK (337)

JSP (20)

Logging (103)

Mail (54)

Messaging (8)

Network (71)

PDF (94)

Report (7)

Scripting (75)

Security (32)

Server (119)

Servlet (17)

SOAP (24)

Testing (50)

Web (19)

XML (301)

Other Resources:

org.apache.commons.lang3.math.Fraction Example

Q

What is org.apache.commons.lang3.math.Fraction class? How to use org.apache.commons.lang3.math.Fraction class?

✍: FYIcenter.com

A

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, 1443👍, 0💬

Popular Posts:

What Is javaws.jar in JRE (Java Runtime Environment) 8? javaws.jar in JRE (Java Runtime Environment)...

What Is fop.jar 0.95? I got it from the fop-0.95-bin.zip. fop.jar (0.95) is the JAR file for FOP 0.9...

How to download and install ojdbc7.jar for Oracle 12c R1? ojdbc8.jar for Oracle 12c R1 is a Java 7 a...

If you are a Java developer, it is very often that you need to use some 3rd party libraries to perfo...

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms, it was develo...