Java 将字符串转换为双精度后出现的问题
我对java是相当陌生的,因此我不知道这为什么不起作用。你能告诉我为什么会出现这个错误吗 我已经导入了java.text.NumberFormat 编译时,我得到:不兼容的类型: 字符串不能转换为双精度 fmt1.formats返回一个字符串,该字符串根据NumberFormat格式化。 double和String是不可更改的类型Java 将字符串转换为双精度后出现的问题,java,double,number-formatting,Java,Double,Number Formatting,我对java是相当陌生的,因此我不知道这为什么不起作用。你能告诉我为什么会出现这个错误吗 我已经导入了java.text.NumberFormat 编译时,我得到:不兼容的类型: 字符串不能转换为双精度 fmt1.formats返回一个字符串,该字符串根据NumberFormat格式化。 double和String是不可更改的类型 final String formatted = fmt1.format(s); 顺便说一句,您在NumberFormat.getCurrencyInstance中
final String formatted = fmt1.format(s);
顺便说一句,您在NumberFormat.getCurrencyInstance中输入了一个错误。您的意思是字符串t=fmt1.formats;这不可能是您的真实代码:getcurrency全部小写?请添加演示您的问题的最小可编译示例。很抱歉,这实际上是getCurrencyInstanceDo我需要将t更改为字符串值吗?谢谢!它在将t更改为字符串值后工作。
final String formatted = fmt1.format(s);