是否有可能做到这一点?
double variable;
variable = 5;
/* the below should return true, since 5 is an int.
if variable were to equal 5.7, then it would return false. */
if(variable == int) {
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
我知道代码可能不会去这样的事情,但怎么也去了?
这是我的简单代码
@Override
public void onClick(View v) {
try {
double price = Double.parseDouble(ePrice.getText().toString());
double percent = Double.parseDouble(ePercent.getText().toString());
double priceValue = price * percent/100.0f;
double percentValue = price - priceValue;
moneyToGet.setText(String.valueOf(priceValue));
moneyToPay.setText(String.valueOf(percentValue));
moneyToGet.setText("" + priceValue);
moneyToPay.setText("" + percentValue);
// catch
} catch (NumberFormatException ex) {
// write a message to users
moneyToGet.setText("");
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是百分比计算器的简单代码.
我想要的是避免我的计算器中的科学记数法因为我不想向用户解释什么是科学记数法.
例如,如果我想计算100,000,000并减少50%,它应该给我50,000,000,这给了我5.0E7而在我的情况下,这对用户没有任何意义.当然,我知道两种结果都是正确的.提前致谢.
我试图使用java从excel表中读取值.当我在excel的单元格中键入10个以上的字母时,它以指数形式显示,如"9.78313E + 2".但这不是我给出的真实数字.任何身体都可以帮助我解决这个问题.如何使用java语言将上述指数形式转换为原始数字.
提前致谢
我正在为JsonSchema使用库com.fasterxml.jackson库,我正在创建一个IntegerSchema对象,当我使用下面的代码设置整数模式的范围时:
main(){
IntegerSchema intSchema = new IntegerSchema();
// setMaximum accepts Double object
intSchema.setMaximum(new Double(102000000));
// setMaximum accepts Double object
intSchema.setMinimum(new Double(100));
printJsonSchema(intSchema);
}
public void printJsonSchema(JsonSchema schema){
ObjectMapper mapper = new ObjectMapper();
try {
logger.info(mapper.writeValueAsString(schema));
} catch (JsonProcessingException e) {
throw new IllegalStateException(e);
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用ObjectMapper将IntegerSchema转换为字符串时得到以下响应:
{"type":"integer","maximum":1.02E8,"minimum":100.0}
Run Code Online (Sandbox Code Playgroud)
最大值和最小值将转换为科学计数法.
但是我需要非科学记谱法的输出如下:
{"type":"integer","maximum":102000000,"minimum":100}
Run Code Online (Sandbox Code Playgroud)
我无法更改IntegerSchema类.
请建议如何在不扩展IntegerSchema类的情况下获得所需的输出?
提前致谢
我有一个xlsx文件,我正在阅读java 6中的apache poi 3.17.在一个实例中,我有一个值为123456789011的单元格.这被读入java作为NUMERIC CellTypeEnum Cell.当我使用DataFormatter获取单元格的值时,如下所示:
DataFormatter formatter = new DataFormatter(Locale.US);
String strVal = formatter.formatCellValue(cell);
字符串值为"1.234567 + 11".我需要单元格中的实际值"123456789011".我怎么能得到它?
我已经尝试在Java中使用BigDecimal转换字符串,但返回"123456700000",因为这是给定信息的最佳效果; 意思是我需要从实际的单元格对象中获取正确的值.我也尝试使用cell.getNumericCellValue()但是它返回一个double,它的限制太小而无法处理原始值,因此它被检索为"1.234567E11",它与其他检索方法具有相同的问题.
有没有办法从原始Cell中获取值作为字符串,因为它是在xlsx中输入的?我对原来的xlsx没有任何威力.
谢谢.
我的代码中有一个浮点数据,我需要从中获取字符串.问题是,当我有像10000000这样的大数字时,它将数字转换为这样的数字:1.0E7
如何将其转换为实际数字?
我们假设我们有以下代码:
System.out.println(String.valueOf(100000000000.0));
Run Code Online (Sandbox Code Playgroud)
现在输出到1.0E11.但这不是我想要的.(在高分上看起来很糟糕)我希望它输出正好100000000000.0.有没有办法做到这一点?
我想将字符串转换为双精度并保持原样,例如我有:
719379705 而不是这个 7.19379705E8
我使用这种方法进行转换:
private double toDouble(String valeur) {
if (valeur != null) {
return Double.parseDouble(valeur);
}
return Double.NaN;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我已经在互联网上搜索过,但找不到任何解决方案(也许,我搜索得很糟糕)。
我想将 转换String "108595000.5"为 adouble并且我使用了这些方法:
Double.parseDouble("108595000.5");
Double.valueOf("108595000.5");
Run Code Online (Sandbox Code Playgroud)
可惜,两人都回来了1.08595E8。
我怎样才能毫无问题地将其转换String为?double
java ×8
double ×3
android ×2
apache-poi ×1
excel ×1
jackson ×1
jsonschema ×1
math ×1
numbers ×1
string ×1