[英]Can't parse String to Long and use it in list
I am getting some values in long getJan();
我在 long
getJan();
from server and has to format this value so that i have some commas and look nicer.来自服务器并且必须格式化此值,以便我有一些逗号并且看起来更好。 And put that values in List that accept longs, but DecimalFormat is returning String.
并将这些值放入接受 long 的 List 中,但 DecimalFormat 返回 String。 I must covert to long so that I can put them in my list.
我必须隐蔽很久才能把他们列入我的名单。 I tried both
Long.valueOf()
and Long.parseLong()
but values are not shown.我尝试了
Long.valueOf()
和Long.parseLong()
但未显示值。
For this post i put only one value but in future it will be more that why I am looping through list.对于这篇文章,我只给出了一个值,但将来它会更多地说明我循环列表的原因。
my code:我的代码:
List<Entry> lista = new ArrayList<>();
NumberFormat myFormat = NumberFormat.getNumberInstance(Locale.US);
myFormat.setGroupingUsed(true);
DecimalFormat decimalFormat = new DecimalFormat("#.00");
decimalFormat.setGroupingUsed(true);
decimalFormat.setGroupingSize(3);
Long jan = Long.parseLong(decimalFormat.format(netWorthPerMonth.getJan()));
// Log.i(TAG, "setSingleLineChart: " + jan);
List<Long> listOfMonth = new ArrayList<>();
listOfMonth.add(jan);
for (int i = 0; i< handleXAxis().size();i++){
lista.add(new Entry(i, listOfMonth.get(i) ));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.