Results 1 to 10 of 10
Thread: Converting double to char array?
 08292010, 12:57 PM #1Member
 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 nonzero 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.
 08292010, 01:13 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,299
 Blog Entries
 7
 Rep Power
 24
 08292010, 01:19 PM #3Member
 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 inbuilt 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; 08292010 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
 08292010, 01:29 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,299
 Blog Entries
 7
 Rep Power
 24
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
 08292010, 01:32 PM #6Member
 Join Date
 Aug 2010
 Posts
 16
 Rep Power
 0
True, thankyou so much.
 08292010, 07:06 PM #7Member
 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?
 08292010, 07:17 PM #8
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,299
 Blog Entries
 7
 Rep Power
 24
 08292010, 07:27 PM #9Member
 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?
 08292010, 07:32 PM #10
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,299
 Blog Entries
 7
 Rep Power
 24
Similar Threads

convert byte array into char array
By kgkamaraj in forum New To JavaReplies: 4Last Post: 09132011, 11:32 AM 
create a 2d char array from a 1D string array
By jschmall12 in forum New To JavaReplies: 1Last Post: 04272010, 09:01 PM 
Converting a char to an int
By michail in forum New To JavaReplies: 10Last Post: 01062010, 10:09 PM 
NullPointerException converting String to double
By infaddict in forum New To JavaReplies: 3Last Post: 07192008, 06:01 PM 
Converting String to Double
By srini in forum New To JavaReplies: 1Last Post: 12242007, 09:03 PM
Bookmarks