OK. I cobbled this together. It works, but is not very idiomatic or efficient. Comments and suggestions welcome...
PHP Code:
public static double round(double numberToRound, int precision)
{
double coefficient = Math_.pow(10, precision);
double numXcoef = numberToRound * coefficient;
// get value left of decimal
String sTempValue = numXcoef + "";
int decPos = sTempValue.length();
for ( int i = 0; i < sTempValue.length(); i++ )
{
char c = sTempValue.charAt( i );
if(c == '.')
{
decPos = i;
}
}
String sLeftOfDecimal = sTempValue.substring(0,decPos);
double LeftOfDecimal = Double.valueOf(sLeftOfDecimal).doubleValue();
// Isolate right side of decimal (RightOfDecimal)
String sRightofDecimal = sTempValue.substring(decPos,sTempValue.length());
double RightOfDecimal = Double.valueOf(sRightofDecimal).doubleValue();
// if greater than or equal to .5, then bump up value returned
if(RightOfDecimal >= .5)
{
LeftOfDecimal = LeftOfDecimal + 1;
}
LeftOfDecimal = LeftOfDecimal / coefficient;
return LeftOfDecimal;
}