小编Kon*_*ken的帖子

使用浮动"可能有损转换"的问题

这是我为我的一个CS课程编写的代码,但我想我还没有正确理解浮动这个术语.它适用于前3次转换,然后它给出了品脱,夸脱和加仑(小数点开始时)的错误.我已经尝试将它们转换为分数,但程序最终会随后吐出0.产生的错误是不兼容的类型:可能从double到float的有损转换

我的代码如下:

import java.lang.*;
import java.util.*;

/* 
Description: This application will be used to convert a user given volume 
in cups to its equivalent number of teaspoons, tablespoons, ounces, pints
quarts, or gallons.

This program will allow us to view what a certain volume of cups would be in
tablespoons, teaspoons etc.

This program will need the number of cups from the user.
Then the program will output the neccessary teaspoons, tablespoons etc.

                    4 cups equals 4 * 48 = …
Run Code Online (Sandbox Code Playgroud)

java floating-point

2
推荐指数
1
解决办法
171
查看次数

标签 统计

floating-point ×1

java ×1