Free Support Forum - aspose.com

Percent Format Style is applied incorrectly under Norwegian Locale

The Norwegian locale specifies that numbers formatted as percentages use a space followed by the percent ‘%’ symbol. Under Aspose Cells for Java version 19.12 - when the Norwegian Locale is specified via the Workbook settings, cells set with the built-in “Percentage” format/style omit the space before the percent symbol.

For example, the following Java code creates two workbooks where the first uses the “EN-US” locale and the second uses “Norwegian (Norway)” locale. After the locale is applied to the workbook, the value 0.2573 is put in cell A1 and the built-in “Percentage” format is applied to the cell. Under the Norwegian locale, the decimal separator symbol ‘,’ is correct - however, the space before the percent symbol ‘%’ is omitted:

import java.text.NumberFormat;

final String fileName = [PATH_TO_SAVE] + "PercentFormat.xlsx";
final double testValue = 0.2573d;

System.out.println("Running on JDK Version: " + 
                   System.getProperty("java.version"));

Locale[] testLocale = { new Locale("en", "US"), new Locale("no", "NO") };
for (Locale curLocale :  testLocale) {

  Workbook wb = new Workbook();
  // Set the workbook to use the current locale
  wb.getSettings().setLocale(curLocale);

  Cell cell = wb.getWorksheets().get(0).getCells().get("A1");
  // put the test value in the cell
  cell.putValue(testValue);

  // Apply the built-in format "Percentage" with 2 decimals
  Style style = cell.getStyle();
  style.setNumber(10);
  style.update();
  cell.setStyle(style);

  System.out.println("Percent format under the locale: " + 
                     curLocale.getDisplayName());
  System.out.println("The Aspose formatted value is : " + 
                     cell.getStringValue());

  // Now use Java's Numberformat on the same value:
  NumberFormat formatter = NumberFormat.getPercentInstance(curLocale);
  formatter.setMinimumFractionDigits(2);
  System.out.println("The Java formatted value is: " + 
                     formatter.format(testValue));

  String newName = fileName.replace(".xlsx", "_" + curLocale.getLanguage() + ".xlsx");
  Files.deleteIfExists(Paths.get(newName));
  wb.save(newName);
  System.out.println("Saved file as: " + newName);
}

When the above code is run under Java 9 or higher, the following is output:

Running on JDK Version: 9.0.4
Percent format under the locale: English (United States)
The Aspose formatted value is: 25.73%
The Java formatted value is  : 25.73%
Saved file as: PercentFormat_en.xlsx
Percent format under the locale: Norwegian (Norway)
The Aspose formatted value is: 25,73%
The Java formatted value is  : 25,73 %
Saved file as: PercentFormat_no.xlsx

Note that for the Norwegian locale, the Java formatted value ‘25,73 %’ correctly shows the space prior to the percent symbol.

Also please note that there seems to have been a fix under Java 9 related to the NumberFormat class and the Norwegian locale. If you run the same code under Java 8, the output becomes:

Running on JDK Version: 1.8.0_77
Percent format under the locale: English (United States)
The Aspose formatted value is: 25.73%
The Java formatted value is  : 25.73%
Saved file as: PercentFormat_en.xlsx
Percent format under the locale: Norwegian (Norway)
The Aspose formatted value is: 25,73%
The Java formatted value is  : 25,73%
Saved file as: PercentFormat_no.xlsx

However, if you modify the Windows’ region settings (under Control Panel > Control Panel\Clock and Region > Change date, time or number formats) to “Norwegian Bokmål (Norway)” and subsequently open either of the two saved workbooks in Excel, you should see that Excel correctly shows the value in cell A1 as ‘25,73 %’.

Thanks.

@oraspose,
Thank you for your query. We are looking into this and will share our feedback soon.

@oraspose,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSJAVA-43086 – Percent Format Style is applied incorrectly under Norwegian Locale

@oraspose,
This is to inform you that we have fixed your issue (logged earlier as “CELLSJAVA-43086”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

The issues you have found earlier (filed as CELLSJAVA-43086) have been fixed in Aspose.Cells for Java v20.1. This message was posted using Bugs notification tool by ahsaniqbalsidiqui