Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

converting decimal to fracational  RSS feed

 
Puter Benda
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a ready made method in java that i convert decimal to fractional.
for example 2.4 => 12 / 5
 
praveen kumaar
Ranch Hand
Posts: 456
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No!
but you can design your own. do use of greatest common divisor. write your own method.
 
Campbell Ritchie
Marshal
Posts: 54882
155
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you use a BigDecimal object, 2.4 ≠ 12 ÷ 5.
 
The knights of nee want a shrubbery. And a tiny ad:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!