@oborza The issue has been closed as Not a Bug
. Here is the analysis:
First things first. The comment in the sample document says:
fr_BE locale default separators
decimal = <comma>
thousands = <space>
It’s not correct (at least for .net and Windows). The number group separator (aka thousands separator) is a dot.
Given this number “12345678.06”
, while using the fr_BE
locale and a number format switch like this # “#.##0,00”
Output is incorrect in AW 23.7.0, output is: $1.234.567.806,00
(it’s like it considers the dot as being thousands separator from the input value)
Your guess is correct. The dot is considered as thousands separator because it is actually thousands separator in Fr-Be. You should pass the value of the numeric type (double/float/decimal) or at least use the correct decimal separator in the string value.
Formatting like this # “# ##0,00”
, using space separator for thousands – doesn’t work, only adds the separator to the first thousands group, why? Output: $12345 678,06
We can not use any char as thousands separator except defined one in current culture (the dot in Fr-Be
). MS Word and AW consider only separators from current culture settings and treat all others as constant symbols with no special meaning. So the space is preserved in output as is.
Format, remove spaces, thousand separator as # “ 0,00” – doesn’t work! How to do the same as #WORDSNET-17, but using as thousand separator, since separator seems that it doesn’t work when used in a switch like this.
There is no way to format results with different separators using only built-in functionality. But there are two APIs that you may use:
Option 1. Document.FieldOptions.FieldUpdatingCallback
:
document.FieldOptions.FieldUpdatingCallback = new FieldUpdatingCallback();
public class FieldUpdatingCallback : IFieldUpdatingCallback
{
public void FieldUpdating(Field field)
{
defaultCulture = CultureInfo.CurrentCulture;
if (string.IsNullOrEmpty(field.Format.NumericFormat))
return;
// The condition is for demonstration purposes only
if (field.Format.NumericFormat.Contains(" "))
{
// Modify an existing culture or create a new one from scratch with expected separators
CultureInfo cultureInfo = new CultureInfo("fr-BE");
cultureInfo.NumberFormat.NumberGroupSeparator = " ";
CultureInfo.CurrentCulture = cultureInfo;
}
}
public void FieldUpdated(Field field)
{
CultureInfo.CurrentCulture = defaultCulture;
}
private CultureInfo defaultCulture;
}
Option 2. Document.FieldOptions.ResultFormatter
:
document.FieldOptions.ResultFormatter = new ResultFormatter();
public class ResultFormatter : IFieldResultFormatter
{
public string FormatNumeric(double value, string format)
{
// Implement custom number formatting here
}
public string FormatDateTime(DateTime value, string format, CalendarType calendarType)
{
return null;
}
public string Format(string value, GeneralFormat format)
{
return null;
}
public string Format(double value, GeneralFormat format)
{
return null;
}
}
Format, thousands separator, # “# ### ### ### ### ### ##0,00"
– works but adds spaces between the currency sign and value, which is not what I want.
MS Word and Aspose.Words insert a space in place of #
if there is no corresponding digit in the field value.
MS Support: #
This format item specifies the requisite numeric places to display in the result. If the result does not include a digit in that place, Word displays a space.
The behavior is the same in AW 21.5 for .NET.