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 8369169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:34:49+00:00 2026-06-09T13:34:49+00:00

Hi i want make so the TextView level can put out decimal but i

  • 0

Hi i want make so the TextView level can put out decimal but i don’ty know how to do that any one got an idea? NOw it only puts out 1 but i want it to put out 1.80. 🙂

public class Main extends Activity {

int counter;
EditText weight, hours;
TextView amount, level;
Button calcuate;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    counter = 0;
    weight = (EditText) findViewById(R.id.weight);
    hours = (EditText) findViewById(R.id.hours);
    amount = (TextView) findViewById(R.id.amount);
    level = (TextView) findViewById(R.id.alcohol_level);
    calcuate = (Button) findViewById(R.id.calcuate);


    final String widmark = getResources().getString(
            R.string.widmark);
    final String hundra = getResources().getString(
            R.string.hundra);
    final String cl = getResources().getString(
            R.string.cl);

    calcuate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Integer wid, mgs;

            String w = weight.getText().toString();
            String h = hours.getText().toString();

            wid = Integer.parseInt(w) * Integer.parseInt(widmark) / Integer.parseInt(hundra);
            mgs = Integer.parseInt(cl) / Integer.parseInt(wid.toString()) / Integer.parseInt(hundra);

            level.setText(mgs.toString());
        }
    });

}

}
  • 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-09T13:34:50+00:00Added an answer on June 9, 2026 at 1:34 pm

    int division will only produce int‘s. If you want your output to be of float or double type, you must use double or float division.

    Double mgs;
    
    mgs = Double.parseDouble(cl) / Double.parseDouble(wid.toString()) / Double.parseDouble(hundra);
    

    Note that not all variables considered in the expression need to be double‘s, only one of them does.

    Another thing that is noteworthy here is whether or not you want two decimal places (assuming a currency here). By default, Java/Android will only spit out as many decimal places as necessary. 1.80 will display as 1.8. To alleviate this, you should use a NumberFormat (specifically, use NumberFormat.getCurrencyInstance()) so that you can specify that you want the number of decimals for your default Locale‘s currency.

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

Sidebar

Related Questions

I want to make a tennis score app but i don't know how to
i want to make an basketball scorekeeper app but i don't know how to
I have TextView and want to use setScaleX()/setScaleY() to make the text zoomable. But
I want to make font in TextView more thinner. How can I do it?
I want to make a universal soundboard. But it won't run, that is strange
i want to set textview text in alertbox. I want to make the countdown
I want make interactive application where user launches it and can do various task
I want to make an application that will grab the HTML from a website
I want to make only one item in the parent list expand at a
I want to make a link for a textview text like Google . Is

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.