Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

converting decimal to fracational  RSS feed

 
Peter Benda
Greenhorn
Posts: 15
  • 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: 461
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: 55747
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you use a BigDecimal object, 2.4 ≠ 12 ÷ 5.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!