# How to input a decimal via JOptionPane and echo it as a Integer

• October 2nd, 2013, 05:10 PM
quantamphysics
How to input a decimal via JOptionPane and echo it as a Integer
I have been assigned to write a program which accepts a certain amount of money in standard form such as "7.53" and echo it as " You have entered 7 dollars and 53 cents", Then before any calculations I am supposed to convert that into an integer amount of cents (753). I wrote this program (shown below) but it only accepts an whole number as my input. What should I do to accept decimals and output successfully as integers?

Code Java:

```  import java.util.*; import javax.swing.*; public class CoinCounter { public static void main (String [] args){ Scanner sc = new Scanner(System.in);   String userInput; int amount; int tooNie = 200; int looNie = 100; int quaRter = 25; int diMe = 10; int nickLes = 5; int peNNies = 1; int totalCoins = 0;   userInput = JOptionPane.showInputDialog("Please enter an amount"); amount = Integer.parseInt(userInput); System.out.println("Enter amount in cents:"); amount=sc.nextInt();     System.out.println((amount / tooNie) + " – Toonies"); amount = amount % 200; System.out.println((amount / looNie) + " – Loonies"); amount = amount % 100; System.out.println((amount / quaRter) + " – Quarters"); amount = amount % 25; System.out.println((amount / diMe) + " – Dimes"); amount = amount % 10; System.out.println((amount / nickLes) + " – Nickles"); amount = amount % 5; System.out.println(amount + " – Pennies");   } }```
• October 2nd, 2013, 05:29 PM
Kewish
Re: How to input a decimal via JOptionPane and echo it as a Integer
• October 2nd, 2013, 06:53 PM
quantamphysics
Re: How to input a decimal via JOptionPane and echo it as a Integer
Sorry I'm new to this posting threads stuff, I posted the previous threads without actually looking at the announcements for beginners, and I thought this one is more easier to read for viewers.
• October 2nd, 2013, 07:55 PM
Kewish
Re: How to input a decimal via JOptionPane and echo it as a Integer
Okay, you're finding your feet. Try and pick up forum etiquette quickly. Not replying to people that take the time to review and respond to your thread comes across as poor etiquette.

In regards to your problem, you say that you cannot take floating point inputs.
Why do you think that is?
What data type are you parsing after input?
What happens when you change that input type to the appropriate one?
Can you manipulate that value using math to make that floating point input represent the integer value you are after? Ie, how do you make 7.53 = 753?