Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method to find # of digits after decimal

 
varun bihani
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any method that will return the number of digits after decimal in double number.
eg, I want to write a method that takes "double number " as input.. I want to know if that number/parameter has any decimal numbers.. ?and how many ?

if parameter is '3' , method should return '0' ..
if parameter is 3.23, it should return '2'..
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not directly, that i know of. It is not a difficult method to write.

Convert the double to a String.

Take the substring you need, return the length. There are special cases to consider, ie 3.0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic