Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Percentage and Deciaml conversion

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I am new to Java. I am trying to figur out how to convert a percentage such as 15% to a decimal like .15 and then converting it back. I have done some serching but I think I am looking and asking for the wrong thing.

Thanks
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andy,
Can you please give more details?
If you are reading the value from STD i/p or calculating it from some other parameters.

If you are asking the user to i/p then it is pretty simple.
You can store it in a double or float variable and divide by 100.
And to convert it back you can multiply by 100 and put a % when you display.
Hope my reply helps you.

Please give more details.

Thanks,
Kashyap
 
Andy Rayburn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much your reply did help.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.text.DecimalFormat

parse()
to convert 15% to 0.15

format()
to convert 0.15 t0 15%
 
reply
    Bookmark Topic Watch Topic
  • New Topic