Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## 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.

2. ## Re: Simple curency convertor

i would like the output answer to be rounded up to 2 significant figures,
Look at the DecimalFormat class.
And also the printf method.

3. ## Re: Simple curency convertor

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)

4. ## 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

5. ## Re: Simple curency convertor

Thanks everyone :-)

6. ## 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

7. ## Re: Simple curency convertor

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