• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I convert a % to a decimal?  RSS feed

 
Cameron O'Neill
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im writing code for a tip calculator. I want the user to be able to enter a percentage value in the console such as 15 or 15% and have the program convert it to .15.

How can I go about doing this?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you do it with pencil and paper?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Err divide it by 100 or have I not understood your question?
 
Cameron O'Neill
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:How would you do it with pencil and paper?


Wow, I'm not thinking today...

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We all have those days...
 
Cameron O'Neill
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the user was to put a % after the number the program would not work. Would there be a way to ignore the % symbol or would it be easier to just say enter the value without the % sign.

I'm doing this for an assignment, I just don't want to lose any marks.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could check to see if the input ended with a % and if so remove it.
 
Cameron O'Neill
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:You could check to see if the input ended with a % and if so remove it.


Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!