DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43940>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.
Advertising
http://issues.apache.org/bugzilla/show_bug.cgi?id=43940
------- Additional Comments From [EMAIL PROTECTED] 2007-11-24 04:31 -------
Performed no timings or comparisons yet, but the result is OK for the mentioned
cases.
How about:
public static void formatDouble(
double source,
int decimals,
int precision,
StringBuffer target) {
boolean isPositive = (source >= 0);
long intPart = (long) (isPositive ? Math.floor(source) :
Math.ceil(source));
int scale = (intPart >= 1) ? decimals : precision;
long fracPart = (long) Math.abs(Math.round((source - intPart) *
Math.pow(10, scale)));
if (intPart != 0 || fracPart != 0) {
/* non-zero value */
if (!isPositive) {
/* negative value, insert sign */
target.append('-');
}
/* append integer part*/
target.append(intPart);
if (fracPart != 0) {
/* append fractional part */
target.append('.');
/* insert leading zeroes */
while (fracPart < Math.pow(10, --scale)) {
target.append('0');
}
target.append(fracPart);
/* remove trailing zeroes */
for (int i = target.length(); --i >= 0 && target.charAt(i) ==
'0'; ) {
target.deleteCharAt(i);
}
}
} else {
target.append('0');
}
}
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.