how to make input number to be like percentage

how to make input number to be like percentage

Page 1 of 1

3 Replies - 3312 Views - Last Post: 30 March 2010 - 08:06 PM Rate Topic: -----

#1 ksaihat  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 27
  • Joined: 11-March 10

how to make input number to be like percentage

Posted 30 March 2010 - 06:25 AM

Hi
How to make input number as a percentage (eg. 3.0)
can i use printf with it?if yes how to do it?

double number;
System.ott.print(enter number as a percentage:);
number=read.nextint();



thanks
Is This A Good Question/Topic? 0
  • +

Replies To: how to make input number to be like percentage

#2 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: how to make input number to be like percentage

Posted 30 March 2010 - 06:43 AM

I'm confused by your question. 3.0 is a decimal, not a percentage, but in order to get a percentage you would have to pick apart the double number and write a method to display it as a percentage. for example, if the user inputs .5, you would have to right a method to do something like multiply it by 100 then display a % sign next to it( just for looks, not math)

also, this will never work

Quote

double number;
System.ott.print(enter number as a percentage:);
number=read.nextint();



it needs to be like this

double number;
System.out.print("Enter number as a percentage: ");
number=read.nextdouble();



I'm assuming you already have created a Scanner objected named read. You must be consistent with your data types or else nothing will work :bigsmile: Best of luck and I'll be happy to help if you have another question
Was This Post Helpful? 1
  • +
  • -

#3 ksaihat  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 27
  • Joined: 11-March 10

Re: how to make input number to be like percentage

Posted 30 March 2010 - 07:00 AM

Hi
put you did not understand what i need

i want to know how to make the percentage number eg.80% to be entered as 8.0


Thanks
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,021
  • Joined: 15-July 08

Re: how to make input number to be like percentage

Posted 30 March 2010 - 08:06 PM

That's called a decimal, not a percentage, as luckless was nice enough to help you with.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1