Simple curency convertor

• September 24th, 2011, 08:41 PM
reddevilggg
Simple curency convertor
I'm a Java beginner, i'm writing a simple program to convert pounds to euros, but i would like the output answer to be rounded up to 2 significant figures, can anybody help. here is the code

import java.util.Scanner;
public class EuroConversion {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);

System.out.println("Enter the amount of pounds to convert");
float money = input.nextInt();

double convertion = money * 1.14;

System.out.println("The convertion is " + convertion + " Euros");

}
}

Thanks for any help.
• September 24th, 2011, 09:01 PM
Norm
Re: Simple curency convertor
Quote:

i would like the output answer to be rounded up to 2 significant figures,
Look at the DecimalFormat class.
And also the printf method.
• September 24th, 2011, 09:10 PM
shia
Re: Simple curency convertor
Quote:

Originally Posted by reddevilggg
I'm a Java beginner, i'm writing a simple program to convert pounds to euros, but i would like the output answer to be rounded up to 2 significant figures, can anybody help. here is the code

import java.util.Scanner;
public class EuroConversion {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);

System.out.println("Enter the amount of pounds to convert");
float money = input.nextInt();

double convertion = money * 1.14;

System.out.println("The convertion is " + convertion + " Euros");

}
}

Thanks for any help.

Formatter (Java Platform SE 6)
• September 24th, 2011, 09:38 PM
mwr76
Re: Simple curency convertor
You could use the String.format() method. It has two parameters . The first is a format identifier, the second is the output string. The identifier starts with
the % symbol. Then you have some optional flags, the width, the significant places, and data type. Here are some examples, and you could do some
searching on Java's String format method: Format a String (JDK1.5) - Real's Java How-to. Also you may want to look into using a named constant for
• September 26th, 2011, 07:35 AM
reddevilggg
Re: Simple curency convertor
Thanks everyone :-)
• September 26th, 2011, 07:51 AM
pushpendra.saraswat@gmail
Re: Simple curency convertor
package examples;

import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);

System.out.println("Enter the amount of pounds to convert");
float money = input.nextFloat();

double convertion = money * 1.14;
DecimalFormat df=new DecimalFormat("#.##");
System.out.println("The convertion is " + df.format(convertion) + " Euros");

}
}

Use this code this will work
• September 26th, 2011, 09:58 AM
copeg
Re: Simple curency convertor
Quote:

Originally Posted by pushpendra.saraswat@gmail
Use this code this will work

You give no reason why the original poster should use that code, nor an explanation of what it does. Please read the forum rules and the following link:
http://www.javaprogrammingforums.com...n-feeding.html