Results 1 to 10 of 10
Thread: Converting double to char array?
- 08-29-2010, 12:57 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 16
- Rep Power
- 0
Converting double to char array?
I have to detect whether a double is a fraction or not.
So, coming from a C background, I thought I should convert the double to an array of chars and check to see if theres any non-zero numbers to the right of the decimal place.
Is this the right way to go about it? If it is, how would i do it?
I don't think I'm allowed to import any packages.
- 08-29-2010, 01:13 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 08-29-2010, 01:19 PM #3
Member
- Join Date
- Aug 2010
- Posts
- 16
- Rep Power
- 0
Thanks man, just a few more questions (I only started learning Java today).
Where do I check out these methods in math class (or any class).
My JRE System library is jdk1.6.0_12, does that affect how many classes I can use?
Is the Math class a basic in-built class that is attached to every java library?
Where can I find all the different classes for my JRE System library (assuming that is where all the classes come from?)
Yes, I'm very noob at java.
EDIT: Also, with your example wouldn't it be x + 1 == Math.ceil(x) or x = Math.ceil(x+1)?Last edited by Blasz; 08-29-2010 at 01:20 PM. Reason: extra question
-
You want to check out the Java API, the latest edition (as of this writing) of which can be found here: Java 1.6 API
- 08-29-2010, 01:29 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
You can bookmark or download the stuff from this link. Java 1.6 is the latest version so you are up to date. Never program anything without checking the API documenation. The Math class is in the java.lang package and that package is included implicitly so you don't have to import anything. For starters read the description of the Math.ceil( ... ) method and you'll see that if x == Math.ceil(x) there is no fractional part in x.
kind regards,
Jos
- 08-29-2010, 01:32 PM #6
Member
- Join Date
- Aug 2010
- Posts
- 16
- Rep Power
- 0
True, thankyou so much.
- 08-29-2010, 07:06 PM #7
Member
- Join Date
- Aug 2010
- Posts
- 16
- Rep Power
- 0
Ok turns out I probably will need to convert a double to a char array as I need to know how many digits there are to the right of the decimal place.
How would I do this?
- 08-29-2010, 07:17 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 08-29-2010, 07:27 PM #9
Member
- Join Date
- Aug 2010
- Posts
- 16
- Rep Power
- 0
Hmm, well this is for a different part of the program. I will need to know how many zero's are right of the decimal if they are all entered but I'm guessing double would just cut them off and keep the value equal to 3.0?
I had a look at DecimalFormat but it looks very daunting, could you explain a little bit of what it does / how I could use it?
- 08-29-2010, 07:32 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
convert byte array into char array
By kgkamaraj in forum New To JavaReplies: 4Last Post: 09-13-2011, 11:32 AM -
create a 2d char array from a 1D string array
By jschmall12 in forum New To JavaReplies: 1Last Post: 04-27-2010, 09:01 PM -
Converting a char to an int
By michail in forum New To JavaReplies: 10Last Post: 01-06-2010, 09:09 PM -
NullPointerException converting String to double
By infaddict in forum New To JavaReplies: 3Last Post: 07-19-2008, 06:01 PM -
Converting String to Double
By srini in forum New To JavaReplies: 1Last Post: 12-24-2007, 08:03 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks