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.
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)
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
your conversion rate.
Re: Simple curency convertor
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
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