Topic: [请教]有没有能把String转成long的method?

  Print this page

1.[请教]有没有能把String转成long的method? Copy to clipboard
Posted by: mitnickcbc
Posted on: 2002-12-12 00:26

Integer.parseInt(String)可以把String转成int,
有没有转成long的?

2.雷同啊 [Re: mitnickcbc] Copy to clipboard
Posted by: rainman
Posted on: 2002-12-12 00:40

Long.parseLong(String)

3.Re:[请教]有没有能把String转成long的method? [Re: mitnickcbc] Copy to clipboard
Posted by: scottding
Posted on: 2002-12-12 09:39

呵,来晚了。

4.Re:[请教]有没有能把String转成long的method? [Re: mitnickcbc] Copy to clipboard
Posted by: archonLing
Posted on: 2002-12-17 14:35

if the String is a formatted Long, ex: 100,000,000,000, then you could get a DecimalFormat instance with the format first. Then use its

public Number parse(String text) or
public Number parse(String text, ParsePosition pos)

methods to get back a Number. Finally, call the longValue() to get back a long.

for example:

long ret = new DecimalFormat("#,##0").parse("100,000,000,000").longValue();

you would need to wrap the code with try..catch block to catch ParseException.

I hope that doesn't confuse you. Heehee... Smile


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923