Java浮点数如何保留小数???

点这里鸭!

例:输入华氏温度f,计算并输出相应的摄氏温度c。c=5*(f-50)/9+10

import java.util.Scanner;
public class practice
{
    public static void main(String[] args)
    {
        //write your own codes
        Scanner input = new Scanner(System.in);
        float f = input.nextFloat();
        float c =5*(f-50)/9+10;
        System.out.println("The temperature is " + (String.format("%.2f",c)));
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_46125998/article/details/115028697
今日推荐