Java 更改设置器1/值(货币)
如何更改setter使其设置为:1/货币。而不仅仅是货币。假设货币是0.1074,我想是1/0.1074=93109Java 更改设置器1/值(货币),java,setter,multiplication,Java,Setter,Multiplication,如何更改setter使其设置为:1/货币。而不仅仅是货币。假设货币是0.1074,我想是1/0.1074=93109 private StringProperty currency = new SimpleStringProperty(); public CurrencyBean(String Currency) { setCurrency(Currency); } public final StringProperty currencyProperty(){ return
private StringProperty currency = new SimpleStringProperty();
public CurrencyBean(String Currency) {
setCurrency(Currency);
}
public final StringProperty currencyProperty(){
return this.currency;
}
//GETTER
public final String getCurrency(){
return this.currencyProperty().get();
}
//SETTER
public final void setCurrency(final String Currency){
this.currencyProperty().set(Currency);
首先,你的二传手不会返回任何东西。它设置了一个字段。对于所描述的内容,您需要解析
货币中的数字
,并在执行计算后将其打印回来。例如
double normalCurrency = Double.parseDouble(Currency);
double reciprocalCurrency = 1/normalCurrency;
String result = Double.toString(reciprocalCurrency);
然后将这个
结果设置到你想要的任何地方我发现了我的问题。。。问题是我的读者读了所有的行。我的csv文件中的第一行只是字符串。。这就是我出错的原因。当我尝试Manos Nikolaidis解决方案时
List<String> lines = Files.readAllLines(Paths.get("currency.csv"), Charset.defaultCharset());
List lines=Files.readAllLines(path.get(“currency.csv”)、Charset.defaultCharset();
因此,如果有人能告诉我如何跳过第一排,我会非常高兴。因为我只知道如何使用bufferedReader跳过第一行。你的setter不会返回任何东西,也不应该返回,那么你到底在说什么?@Stultuske哦,我的意思是我想将值设置为1/currency。现在编辑我的BAD为什么要使用字符串
?它看起来像这样?这个.currencyProperty().set(result)在我的setter方法中?@Dolle我不知道什么是StringProperty
,但它似乎是对的。什么是StringProperty
?可能您必须使用this.currencyProperty().setValue(结果)代码>StringProperty用于javafx设置值也不起作用。我的e.Message说“输入字符串”是货币
只是数字,例如“0.1074”
?字符串后面还有其他字母吗?