Changeset 4216


Ignore:
Timestamp:
Apr 10, 2008, 2:23:25 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #985: File sizes are not correctly rounded

Also fixed so that the number of decimals follow the preferences from File -> Preferences

Location:
branches/2.6-stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6-stable/src/core/net/sf/basedb/util/Values.java

    r4034 r4216  
    659659    {
    660660      long lNumber = (long)fNumber;
     661      long remain = Math.round(fNumber*exp-lNumber*exp);
     662      if (remain >= exp)
     663      {
     664        remain -= exp;
     665        lNumber++;
     666      }
     667      String theDecimals = Long.toString(remain);
    661668      result.append(lNumber).append(".");
    662       String theDecimals = Long.toString(Math.round(fNumber*exp-lNumber*exp));
     669      result.append(theDecimals);
    663670      if (theDecimals.length() < decimals)
    664671      {
     
    668675        }
    669676      }
    670       result.append(theDecimals);
    671677    }
    672678    if (unit != null) result.append(unit);
     
    687693  public static final String formatBytes(Long bytes)
    688694  {
     695    return formatBytes(bytes, 1);
     696  }
     697 
     698  /**
     699    Formats a value using units of bytes, kilobytes, megabytes or gigabytes.
     700    @param bytes The value to format
     701    @param decimals The number of decimals to display in KB, MB, and GB values
     702    @since 2.6.2
     703  */
     704  public static final String formatBytes(Long bytes, int decimals)
     705  {
    689706    if (bytes == null) return "";
    690707    if (bytes >= GB)
    691708    {
    692709      float gb = (float)bytes / GB;
    693       return formatNumber(gb, 1)+" GB";
     710      return formatNumber(gb, decimals)+" GB";
    694711    }
    695712    else if (bytes >= MB)
    696713    {
    697714      float mb = (float)bytes / MB;
    698       return formatNumber(mb, 1)+" MB";
     715      return formatNumber(mb, decimals)+" MB";
    699716    }
    700717    else if (bytes >= kB)
    701718    {
    702719      float kb = (float)bytes / kB;
    703       return formatNumber(kb, 1)+" kB";
     720      return formatNumber(kb, decimals)+" kB";
    704721    }
    705722    else
  • branches/2.6-stable/www/filemanager/files/list_files.jsp

    r4003 r4216  
    5959  import="net.sf.basedb.clients.web.util.HTML"
    6060  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
     61  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
    6162  import="net.sf.basedb.util.Values"
    6263  import="net.sf.basedb.util.formatter.Formatter"
     
    150151  int numListed = 0;
    151152  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
     153  int numDecimals = FormatterSettings.getNumDecimals(sc);
    152154  %>
    153155  <base:page title="<%=title==null ? "Files" : title%>" type="popup">
     
    817819                  onclick="fileOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)"
    818820                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
    819                 <tbl:cell column="size"><%=Values.formatBytes(item.getSize())%></tbl:cell>
    820                 <tbl:cell column="compressedSize"><%=Values.formatBytes(item.getCompressedSize())%></tbl:cell>
     821                <tbl:cell column="size"><%=Values.formatBytes(item.getSize(), numDecimals)%></tbl:cell>
     822                <tbl:cell column="compressedSize"><%=Values.formatBytes(item.getCompressedSize(), numDecimals)%></tbl:cell>
    821823                <tbl:cell column="compressed"><%=item.isCompressed() ? "yes" : "no"%></tbl:cell>
    822824                <tbl:cell column="writeProtected"><%=item.isWriteProtected() ? "yes" : "no"%></tbl:cell>
Note: See TracChangeset for help on using the changeset viewer.