Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-07-2008, 12:18 PM
Member
 
Join Date: Jun 2008
Posts: 2
coolsig is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-07-2008, 03:27 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
try biginteger
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-07-2008, 03:49 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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.

Code:
String c = "848595950484765868574748349586738596879"; try { BigDecimal num2 = new BigDecimal(new Double(c)); System.out.println(num2); } catch (NumberFormatException nfe) { nfe.printStackTrace(); }
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by sukatoa : 06-07-2008 at 03:52 PM. Reason: Typo
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-07-2008, 08:10 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
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); } }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-07-2008, 08:33 PM
Member
 
Join Date: Jun 2008
Posts: 2
coolsig is on a distinguished road
Thanks,
It worked
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-08-2008, 08:18 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
You may now mark this thread as SOLVED....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-14-2008, 03:48 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 191
danielstoner is on a distinguished road
Also look at this thread

how to convert from BigInteger to Hex
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert string to a double? javaMike Advanced Java 2 11-27-2007 04:10 AM
convert string to float miss_dot NetBeans 1 11-15-2007 12:26 AM
How to convert a string into a BigInteger valery New To Java 1 08-06-2007 09:36 PM
how to convert String number to int gabriel New To Java 3 08-02-2007 05:46 AM
Error: convert from String to long bbq New To Java 1 06-29-2007 08:23 PM


All times are GMT +3. The time now is 04:07 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org