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

  • SEARCH
  • Home
  • 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 8417537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:04:40+00:00 2026-06-10T02:04:40+00:00

I am trying to write a program that stores money in a variable, so

  • 0

I am trying to write a program that stores money in a variable,
so I am using Bigdecimal type as it was advised by other memebers here..
But what I am trying to do is this.. user can type in what ever way he wants means to say, he can type

 24
 or
 24.0
 or
 24.00

so as you can see that I am giving the user flexibility to type at his own convenience. But in the end the variable will be stored in an array (BigDecimal array) so when it stores I want to store with and only 2decimal places. Why I say that is if the user types in 24 I want to store 24.00 NOT 24 or 24.0 JUST 24.00 or if he enters 24.00 then that will be stored with out any modification done to it.. how to do this..
Sample code provided below.

    BigDecimal bala;
    BigDecimal balintake;
    static BigDecimal[] bal= new BigDecimal[20];
    Scanner sc = new Scanner(System.in);
    balintake = sc.nextBigDecimal();

     bala.setScale(2,RoundingMode.HALF_UP);
     bal[0] = bala;

But this is not working as according to my requirements.

  • 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-06-10T02:04:42+00:00Added an answer on June 10, 2026 at 2:04 am

    Remember that BigDecimal objects are immutable. So, when you do

    balintake.setScale(2,RoundingMode.HALF_UP);
    

    you should assign it to back to a variable, like

    balintake = balintake.setScale(2,RoundingMode.HALF_UP);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to write a program that stores the message in a string
I'm trying to write a program that can stop and start services using SilverLight
I'm trying to write a program that takes a large file (of any type)
I trying to write a program that navigates the local file system using a
I'm trying to write a program that would convert celcius to fahrenheit and visa-versa.
I am trying to write a program that will prompt you to enter someone's
I am trying to write a program that sends basic text files from one
I am trying to write a program that allows a binary to be run,
I am trying to write a program that displays the integers between 1 and
i am trying to write a program that close explorer then runs another program.

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.