Changeset 4216
- Timestamp:
- Apr 10, 2008, 2:23:25 PM (15 years ago)
- 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 659 659 { 660 660 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); 661 668 result.append(lNumber).append("."); 662 String theDecimals = Long.toString(Math.round(fNumber*exp-lNumber*exp));669 result.append(theDecimals); 663 670 if (theDecimals.length() < decimals) 664 671 { … … 668 675 } 669 676 } 670 result.append(theDecimals);671 677 } 672 678 if (unit != null) result.append(unit); … … 687 693 public static final String formatBytes(Long bytes) 688 694 { 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 { 689 706 if (bytes == null) return ""; 690 707 if (bytes >= GB) 691 708 { 692 709 float gb = (float)bytes / GB; 693 return formatNumber(gb, 1)+" GB";710 return formatNumber(gb, decimals)+" GB"; 694 711 } 695 712 else if (bytes >= MB) 696 713 { 697 714 float mb = (float)bytes / MB; 698 return formatNumber(mb, 1)+" MB";715 return formatNumber(mb, decimals)+" MB"; 699 716 } 700 717 else if (bytes >= kB) 701 718 { 702 719 float kb = (float)bytes / kB; 703 return formatNumber(kb, 1)+" kB";720 return formatNumber(kb, decimals)+" kB"; 704 721 } 705 722 else -
branches/2.6-stable/www/filemanager/files/list_files.jsp
r4003 r4216 59 59 import="net.sf.basedb.clients.web.util.HTML" 60 60 import="net.sf.basedb.clients.web.formatter.FormatterFactory" 61 import="net.sf.basedb.clients.web.formatter.FormatterSettings" 61 62 import="net.sf.basedb.util.Values" 62 63 import="net.sf.basedb.util.formatter.Formatter" … … 150 151 int numListed = 0; 151 152 Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc); 153 int numDecimals = FormatterSettings.getNumDecimals(sc); 152 154 %> 153 155 <base:page title="<%=title==null ? "Files" : title%>" type="popup"> … … 817 819 onclick="fileOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 818 820 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> 821 823 <tbl:cell column="compressed"><%=item.isCompressed() ? "yes" : "no"%></tbl:cell> 822 824 <tbl:cell column="writeProtected"><%=item.isWriteProtected() ? "yes" : "no"%></tbl:cell>
Note: See TracChangeset
for help on using the changeset viewer.