This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am dealing with data from a mainframe where all the fields are String data types. However some of the fields have deciaml(currency) values that I need to be able to convert to a BIGINTEGER data type and since BigInteger has no constructor that utilizes int I am lost at getting this string to a BigInteger. Any help or direction would be appreciated.
Here is the method that I started with and its blowing up because the bolded values below contain decimal values that are a String data type.
You are correct that the String value is like "8.54" and that BigInteger does handle integers. I was trying to get the value ultimately to a cents value such as 854. I did not want the number rounded as I understood that BigDecimal would ultimately do.
Am I understanding that correctly?
Thanks for the reply. [ October 18, 2005: Message edited by: Melinda Savoy ]
Joined: Sep 16, 2005
With simple strings like that, I would extract the dollar and cents substrings directly and avoid floating point rounding worries. For example:
This assumes that your values won't overflow a 32-bit int, and your code may need to consider cases like "12" and ".34" and "-4.33".
If you can safely assume that your values won't overflow 32 bits, then you shouldn't use BigInteger. BigInteger introduces a lot of overhead that is unnecessary if you can store your values as an int or long. You should be able to take the example above and combine the dollars and cents into a single int value.