Results 1 to 7 of 7
- 06-07-2008, 11:18 AM #1
Member
- Join Date
- Jun 2008
- Posts
- 2
- Rep Power
- 0
convert a really big string (len 39) to bigdecimal
Hi ,
How do I convert a large String (length 39 ) to BigDecimal ?
eg
String c = "848595950484765868574748349586738596879";
try {
BigDecimal num2 = BigDecimal.valueOf((Long.parseLong(c)));
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
}
I tried this, it throws a nfe. Any ideas on how to get this string parsed to an BigDecimal.
Thanks
- 06-07-2008, 02:27 PM #2
try biginteger
My IP address is 127.0.0.1
- 06-07-2008, 02:49 PM #3
The way you initialize BigDecimal is strange for me....
I guess you should initialize first an Instance of it before you use valueOf(something) method....
But it may be simplified....
According to your string sample, that value may not be applicable to long, see what's the maximum value can long datatype handles...
You may also try Double,
eg.
Java Code:String c = "848595950484765868574748349586738596879"; try { BigDecimal num2 = new BigDecimal(new Double(c)); System.out.println(num2); } catch (NumberFormatException nfe) { nfe.printStackTrace(); }Last edited by sukatoa; 06-07-2008 at 02:52 PM. Reason: Typo
freedom exists in the world of ideas
- 06-07-2008, 07:10 PM #4
Java Code:import java.math.BigDecimal; public class Test { public static void main(String[] args) { String c = "848595950484765868574748349586738596879"; BigDecimal num2 = null; try { num2 = new BigDecimal(c); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } System.out.println("num2 = " + num2); } }
- 06-07-2008, 07:33 PM #5
Member
- Join Date
- Jun 2008
- Posts
- 2
- Rep Power
- 0
Thanks,
It worked :)
- 06-08-2008, 07:18 AM #6
You may now mark this thread as SOLVED....
freedom exists in the world of ideas
- 06-14-2008, 02:48 AM #7
Also look at this thread
how to convert from BigInteger to HexDaniel @ [www.littletutorials.com]
Language is froth on the surface of thought
Similar Threads
-
How to convert a string into a BigInteger
By valery in forum New To JavaReplies: 4Last Post: 09-13-2011, 01:32 PM -
how to convert String number to int
By gabriel in forum New To JavaReplies: 5Last Post: 08-02-2009, 03:46 PM -
convert string to a double?
By javaMike in forum Advanced JavaReplies: 2Last Post: 11-27-2007, 03:10 AM -
convert string to float
By miss_dot in forum NetBeansReplies: 1Last Post: 11-14-2007, 11:26 PM -
Error: convert from String to long
By bbq in forum New To JavaReplies: 1Last Post: 06-29-2007, 07:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks