简体   繁体   English

Java格式将double转换为String

[英]Java formatted converting double to String

I have this: 我有这个:

double indPay;
double indPayment[];
DecimalFormat myFormat = new DecimalFormat("##.00");

But when I do this: 但是当我这样做时:

indPay = myFormat.format(indPayment[q]);

I get: Type mismatch. Cannot convert from String to double. 我得到: Type mismatch. Cannot convert from String to double. Type mismatch. Cannot convert from String to double.

Why is this? 为什么是这样?

EDIT: Is there any way of formatting a double without going thru this string process? 编辑:有没有通过此字符串过程格式化双精度格式的任何方法?

indPay is a double and you are trying to store a string in it; indPay是双精度型,您正在尝试在其中存储一个字符串; try String str = myFormat.format(indPayment[q]); 试试String str = myFormat.format(indPayment[q]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM