On Fri, 9 Sep 2022 08:11:56 GMT, Abhishek Kumar <[email protected]> wrote:
>> src/java.desktop/share/classes/sun/swing/FilePane.java line 1277:
>>
>>> 1275: DecimalFormat df = new DecimalFormat("0.0");
>>> 1276: double val = fileSize/baseFileSize;
>>> 1277: return Double.valueOf(df.format(val));
>>
>> The new code to round up looks difficult to understand (I mean the addition
>> of 99 and re-worked if-conditions). I liked the previous version better. The
>> only thing required to introduce rounding up is updating
>> `roundToOneDecimalPlace`:
>>
>>
>> private static double roundToOneDecimalPlace(long fileSize) {
>> return Math.ceilDiv(fileSize, 100L) / 10.0d;
>> }
>>
>>
>> [`Math.ceilDiv`](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/Math.html#ceilDiv(long,long))
>> is available since Java 18.
>>
>> However, this code also works and is better suited for backporting:
>>
>>
>> private static double roundToOneDecimalPlace(long fileSize) {
>> return Math.ceil(fileSize / 100.0d) / 10.0d;
>> }
>>
>> Note that the first division is also floating point.
>>
>> With this implementation of `roundToOneDecimalPlace` and your code before
>> the latest update which introduced `+99`, I get the expected size displayed
>> in `JFileChooser`, that is rounded up if there's a non-zero remainder. Could
>> you please verify that?
>
> I have checked with the suggested changes, it rounds up the value if the
> remainder is non-zero value.
> But for files >1000 bytes it doesn't return the file size similar to native
> file manager.
>
> FileChooser rounded up the values to next decimal precision.
> 
>
> File sizes are not rounding up in all cases in native file system. For e.g.
> 1150 bytes file size is is 1.1 KB whereas 1151 bytes file size is 1.2 KB.
> 
>
> To keep it consistent with the native file system for larger files (>1000
> bytes), I tried using DecimalFormat.
To clarify: Abhishek and I were discussing the approach, it's still
*inconsistent* in the same way: the file size was rounded up if it's less than
1 KB, but rounded (down) if it's larger.
The native file manager in Ubuntu rounds the file size.
`JFileChooser` does not display bytes that's why we round up the size. To avoid
confusion, the size displayed in `JFileChooser` is always rounded up as Phil
@prrace suggested.
-------------
PR: https://git.openjdk.org/jdk/pull/9327