/** * Format a real number to the precision specified. Does not round the number * or truncate trailing zeros. * * @param value real number to format * @param precision # of digits after the decimal place * @return formatted string */ public static String formatDecimal( double value, int precision) { return formatDecimal(value, precision, TRUNCZEROS_NO, ROUND_NO); }
/** * Print the BITS/second in an international format. * @param n - always formatted using SI (i.e. decimal) prefixes * @return String in an internationalized format. * @deprecated Dunno who thought this was a good idea to use decimal calc but binary/decimal selected unit text */ public static String formatByteCountToBitsPerSec( long n) { double dbl = n * 8; int unitIndex = UNIT_B; long div = 1000; while (dbl >= div && unitIndex < unitsStopAt){ dbl /= div; unitIndex++; } int precision = UNITS_PRECISION[unitIndex]; return( formatDecimal(dbl, precision, true, true) + units_bits[unitIndex] + per_sec ); }
public static String formatByteCountToKiBEtc( long n, boolean rate, boolean bTruncateZeros, int precision) { double dbl = (rate && use_units_rate_bits) ? n * 8 : n; int unitIndex = UNIT_B; long div = force_si_values?1024:(use_si_units?1024:1000); while (dbl >= div && unitIndex < unitsStopAt){ dbl /= div; unitIndex++; } if (precision < 0) { precision = UNITS_PRECISION[unitIndex]; } // round for rating, because when the user enters something like 7.3kbps // they don't want it truncated and displayed as 7.2 // (7.3*1024 = 7475.2; 7475/1024.0 = 7.2998; trunc(7.2998, 1 prec.) == 7.2 // // Truncate for rest, otherwise we get complaints like: // "I have a 1.0GB torrent and it says I've downloaded 1.0GB.. why isn't // it complete? waaah" return formatDecimal(dbl, precision, bTruncateZeros, rate) + (rate ? units_rate[unitIndex] : units[unitIndex]); }
return formatDecimal(dbl, precision, bTruncateZeros, rate) + (rate ? units_rate[unitIndex] : units[unitIndex]);
System.out.println("NF/6: " + s); // Displays 0.000004 System.out.println("DF: " + DisplayFormatters.formatDecimal(d , 6)); System.out.println("DF 0: " + DisplayFormatters.formatDecimal(d , 0)); System.out.println("0.000000:" + DisplayFormatters.formatDecimal(0 , 6)); System.out.println("0.001:" + DisplayFormatters.formatDecimal(0.001, 6, TRUNCZEROS_YES, ROUND_NO)); System.out.println("0:" + DisplayFormatters.formatDecimal(0 , 0)); System.out.println("123456:" + DisplayFormatters.formatDecimal(123456, 0)); System.out.println("123456:" + DisplayFormatters.formatDecimal(123456.999, 0)); System.out.println(DisplayFormatters.formatDecimal(0.0/0, 3));
public String getDoubleAverageAsString( int precision ) { return( DisplayFormatters.formatDecimal( getDoubleAverage(), precision )); }
/** * Prints byte value in BITS/second in either binary or decimal units as required * @param n byte count * @return */ public static String formatByteCountToBitsPerSec2( long n) { double dbl = n * 8; int unitIndex = UNIT_B; long div = getKinB(); while (dbl >= div && unitIndex < unitsStopAt){ dbl /= div; unitIndex++; } int precision = UNITS_PRECISION[unitIndex]; return( formatDecimal(dbl, precision, true, true) + units_bits[unitIndex] + per_sec ); }
private void generateEvidence( IndentWriter writer ) { writer.println( name + ": max=" + max_size +",qwf=" + queue_when_full + ",queue=" + task_queue.size() + ",busy=" + busy.size() + ",total=" + task_total + ":" + DisplayFormatters.formatDecimal(task_average.getDoubleAverage(),2) + "/sec"); }
String arg4 = DisplayFormatters.formatDecimal(req_out_rate,1) + "/" + DisplayFormatters.formatDecimal(req_in_rate,1);
", ratio=" + DisplayFormatters.formatDecimal(last_incomplete_average/last_complete_average, 2) + "]";
sr_str = DisplayFormatters.formatDecimal((double) sr / 1000, 3);
"sr_prog.window.title", "sr_prog.window.message"); String sr_str = DisplayFormatters.formatDecimal((double) existing_sr / 1000, 3);
@Override public void refresh(TableCell cell) { DownloadManager dm = (DownloadManager)cell.getDataSource(); int sr = (dm == null) ? 0 : dm.getStats().getShareRatio(); if ( sr == Integer.MAX_VALUE ){ sr = Integer.MAX_VALUE-1; } if ( sr == -1 ){ sr = Integer.MAX_VALUE; } if (!cell.setSortValue(sr) && cell.isValid()) return; String shareRatio = ""; if (sr == Integer.MAX_VALUE ) { shareRatio = Constants.INFINITY_STRING; } else { shareRatio = DisplayFormatters.formatDecimal((double) sr / 1000, 3); } if( cell.setText(shareRatio) && changeFG ) { Color color = sr < iMinShareRatio ? Colors.colorWarning : null; cell.setForeground(Utils.colorToIntArray(color)); } }
s = "1:" + Constants.INFINITY_STRING; else s = DisplayFormatters.formatDecimal(value, 2) + ":1";
s = "1:" + Constants.INFINITY_STRING; else s = DisplayFormatters.formatDecimal(value, 2) + ":1";
protected String getMapperTitle( SpeedManagerPingMapper mapper ) { if ( mapper.isActive()){ SpeedManagerLimitEstimate up_1 = mapper.getEstimatedUploadLimit(false); SpeedManagerLimitEstimate up_2 = mapper.getEstimatedUploadLimit(true); SpeedManagerLimitEstimate down_1 = mapper.getEstimatedDownloadLimit(false); SpeedManagerLimitEstimate down_2 = mapper.getEstimatedDownloadLimit(true); return( "ul=" + DisplayFormatters.formatByteCountToKiBEtc(up_1.getBytesPerSec()) + ":" + DisplayFormatters.formatByteCountToKiBEtc(up_2.getBytesPerSec())+ ",dl=" + DisplayFormatters.formatByteCountToKiBEtc(down_1.getBytesPerSec()) + ":" + DisplayFormatters.formatByteCountToKiBEtc(down_2.getBytesPerSec()) + ",mr=" + DisplayFormatters.formatDecimal( mapper.getCurrentMetricRating(),2)); } return( "" ); }
cell.setText("??"); } else { cell.setText(DisplayFormatters.formatDecimal(ratio, 3));
String sr_str = DisplayFormatters.formatDecimal((double) sr / 1000, 3);