Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:17:55+00:00 2026-05-26T23:17:55+00:00

Almost everything I’ve ever read about Java says don’t use float or double for

  • 0

Almost everything I’ve ever read about Java says don’t use float or double for currency, but it seems like everything in Swing tries to force you to do exactly that if you want to input / display currency values that have decimal places (aka exactly what most people want to do).

I can use NumberFormat.getCurrencyInstance() with a NumberFormatter and JFormattedTextField, but I can’t figure out how to get it to display decimal places without using Float or Double. I’ve got to be overlooking something simple.

How can I make my currency fields display $1.55, accept input as 1.55 and store the input as an Integer with a value of 155 (cents)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:17:55+00:00Added an answer on May 26, 2026 at 11:17 pm

    You cannot do math on formatters. What you should do is have a member variable of your pojo holding the price in cents. Something like:

    private long priceInDollarCents;
    

    Then you can have a getter which will return this in dollars. Something like:

    public double getPriceInDollars() {
        return (double)priceInDollarCents/100;
    }
    

    This is what you’ll pass into your formatter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At work we do almost everything in Java and perl, but I wanted to
Almost every Java book I read talks about using the interface as a way
I know that almost everything is already said about CMSs, but what interests me
It seems you can assign a keyboard shortcut to almost everything else, but I
At the moment I use PHP for almost everything I develop for the Web
I have a project for a course, I did almost everything but I have
I like to use python for almost everything and always had clear in my
I've tried almost everything imaginable (apart from the right thing of course), but still
I've just setup a wordpress MU install and almost everything seems to be in
Here's my ExtJs component. Everything works perfectly.... err well almost everything. I just don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.