Part VII: Convert from a double WITH OR WITHOUT A FRACTIONAL PART to a hexaicosadecimal string
Again, we're building on our solution from Part VI, in which we solved for a double that did not have a fractional part. We're about to relax that restriction, so now our input doubles can have a fractional part as well as a whole number part.
First, we have to get the fractional part. In Part VI, we got the whole number part by converting the double to an integer type. To get the fractional part, all we have to do is subtract the integer from the double.
If the fractional part is zero, the solution is the same as in Part VI. If the fractional part is NON zero, things get a bit trickier. There are multiple ways to solve this problem, but the easiest one is to essentially use the same method we did in Part V. However, before we can use that same algorithm, we have to convert the fractional part to a corresponding integer type value. (For example, if the fractional part was 0.25, the corresponding integer type value would be 25; if the fractional part was 0.12345, the corresponding integer type value would be 12345. In short, you need to move the decimal point to the right end of the number.) If we could do that, we'd be set; we'd just be able to run the algorithm from Part V once on the whole number part, put a "" in the middle, and then run it again on the corresponding integer for the fractional part.
I'm leaving the rest to you. There are a number of ways to generate the corresponding integer values for a fractional part. You have all the tools you need already; it can be done in a handful of lines with just a loop and basic Java mathematical operations. (But a more elegant solution might be found if you look into other Java classes, such as the BigDecimal class...)
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.