Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Java Java-conversion Convert Decimal To Fraction

Related Tutorials


Share on Google+Share on Google+

Convert Decimal To Fraction

In this example, you will learn how to convert decimal number to Fraction.

Convert Decimal To Fraction


In this example, you will learn how to convert decimal number to Fraction. The following program you convert it into the decimal to fraction value by using doubleValue() method..

Code description:

In this program you will also learn how to convert a decimal number into fraction with the help of valueOf() method. Define the class named "DecimalToFraction" for the java component. This program takes a string type value and store it in an integer type variable by using parseInt() method which converts decimal number into fraction by using doubleValue() method.

Here is the code of this program:

import java.lang.*;

public class DecimalToFraction{

  public static void main(String args[]) throws IOException{
  BufferedReader buf = 
BufferedReader(new InputStreamReader(;
  System.out.println("Enter the decimal number");
  String s = buf.readLine();
  int in = Integer.parseInt(s);
  double d= Double.valueOf(in).doubleValue();
  System.out.println("Fraction is:=" + d);

Download of this program:

Output of this program.

C:\corejava>java DecimalToFraction
Enter the decimal number
Fraction is:=23.0

If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 10, 2007

Related Tutorials

Discuss: Convert Decimal To Fraction   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image