如何在Java中将15%更改为0.15?
因此,我正在制作一个基本的小费计算器,我需要知道如何将用户输入的15%、23%等更改为0.15、0.23等 这是我当前的代码:如何在Java中将15%更改为0.15?,java,calculator,Java,Calculator,因此,我正在制作一个基本的小费计算器,我需要知道如何将用户输入的15%、23%等更改为0.15、0.23等 这是我当前的代码: import java.util.Scanner; public class TipCalc { public static void main(String args[]) { Scanner meal = new Scanner(System.in); double food, tax, tip, fin; S
import java.util.Scanner;
public class TipCalc {
public static void main(String args[]) {
Scanner meal = new Scanner(System.in);
double food, tax, tip, fin;
System.out.println("How much was the meal?");
food = meal.nextDouble();
System.out.println("How much was the tax?");
tax = meal.nextDouble();
System.out.println("How much would you like to tip? I recomend 15%");
tip = meal.nextDouble();
}
}
请帮忙!谢谢
double tip;
tip = meal.nextDouble() / 100;
或
甚至
double tip = 15.0;
tip /= 100;
或
甚至
double tip = 15.0;
tip /= 100;
如果您的提示输入为15 使用
如果提示的输入为15,则输出为:0.15 使用 将输出:0.15
tip=fine.nextInt()/100.0代码>最重要的错误:推荐tip=deal.nextInt()/100.0代码>最重要的错误:推荐
tip = meal.nextDouble() / 100.0;
System.out.println(tip);