Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Colleen Burton   on Jan 16 In Java Category.

  
Question Answered By: Shelia Wells   on Jan 16

I can help you regarding the first problem.
Using the following method you do precesion upto any value.

/**
* This method provides a more sophisticated use of Math.round(double)
* for getting the the precision values.
*
* @param value The value to round.
* @param precision The basically an indicator of what digit to apply round
to.
* @return The resultant value.
*/
public static final float getPrecisionRound (float value, int precision) {
String sPattern = "####.0";
for (int i=1;i<precision ; i++)
sPattern += "0";
java.text.DecimalFormat df = new java.text.DecimalFormat (sPattern);
return Float.parseFloat (df.format(value));
}

So you should call this method as ---> getPrecisionRound (1.12345,3)
Here
1.12345 => The number you want to do precision.
3 => round it and just keep three digit after " ."

Share: 

 

This Question has 11 more answer(s). View Complete Question Thread

 


Tagged: