How do you reverse a decimal number like 0.5
<p>My question is how can you reverse a decimal in java? </p>

<p>Numbers such as 0.5 , 0.8 etc.. </p>

<p>All my attempts at reproducing this code using a double variable instead of an int have literally caused my terminal to output " Infinity " or the symbol for infinity.</p>

<pre><code>import java.util.*; 
public class Example
{
    public static void main(String[] args)
    {                       
        int d = 0, 
               Result = 0;

        Scanner in = new Scanner(System.in); 

        System.out.print("enter a number: ");

        d = Integer.parseInt(in.nextLine()); 

        while(d &gt; 0)
        { 
            Result = (Result * 10) + d % 10; 
            d = d / 10;
        } 

        System.out.println("\nThe Reversed Number Is: " + Result);          

    }
} 
</code></pre>

<p>EDIT: Sorry guys I meant to put the output in.</p>

<p>So if you were to run this program the output would look like this (depending on the numbers you enter)</p>

<pre><code>enter a number: 123456789

The Reversed Number Is: 987654321 
</code></pre>

<p>My desired output would look like the following</p>

<pre><code>Enter a decimal number: 0.5

The Reversed number is: 5.0 


import java.util.*; 
public class Example
{
    public static void main(String[] args)
    {                       
        double d = 0, 
               Result = 0;

        Scanner in = new Scanner(System.in); 

        System.out.print("enter a number: ");

        //d = Double.parseDouble(in.nextLine()); 
        //^ That will not cut off any result lol

        d = in.nextDouble(); 

        while(d &gt; 0)
        { 
            Result = (Result * 10) + d % 10; 
            d = d / 10;
        } 

        System.out.println("\nThe Reversed Number Is: " + Result);          

    }
} 

enter a number: 0.5

The Reversed Number Is: Infinity
// The above result used d = Double.parseDouble(in.nextLine()) 



 //The below output used d = in.nextDouble(); 
</code></pre>

<p>The only difference between those two methods of accepting input 
is that one accounts for people not following directions and the other doesn't
There is of course no try or catch etc.. or any thing here to terminate if any thing but a number is input and there does not need to be. The point is both of those input methods will generate the same results</p>

<pre><code>enter a number: 5.0

The Reversed Number Is: Infinity
</code></pre>