We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to format the currency and negative symbol using .NET

After upgrade Aspose.Word 13.5 to 19.12 we run into one Number Format issue with Currency and Negative symbol.
We observed extra space(s) between Currency/Negative symbol and actual value.

So, we get $ 123.55 which used to be $123.55. The merge field format in this case is “#,##0.00”.
By removing the # will work but I want to know if there is a solution for this?.

Ideally, new version should be backward compatible and we don’t need to make major changes to function our existing functionality.

@Rakesh2013

Please check the code example shared in the following link.

https://apireference.aspose.com/words/net/aspose.words.fields/ifieldresultformatter

It would be great if you please share some detail about your issue along with documents and code example to reproduce your issue at our end. We will investigate the issue and provide you more information on it.

Hello Tahir,

I have updated main question and provided more details about my issue.
I have also attached here sample application to reproduce it.

POC-CurrencyFormatIssue.zip (4.8 MB)

@Rakesh2013

Please use FieldOptions.LegacyNumberFormat property as shown below to get the desired output.

Please note that when this property is set to true, template symbol “#” worked as in .net: Replaces the pound sign with the corresponding digit if one is present; otherwise, no symbols appears in the result string.

Moreover, when this property is set to false, template symbol “#” works as MS Word: This format item specifies the requisite numeric places to display in the result. If the result does not include a digit in that place, MS Word displays a space. For example, { = 9 + 6 # $### } displays $ 15.

Document document = new Document(MyDir + "TestUSLocale.docx");
document.FieldOptions.LegacyNumberFormat = true; 
document.MailMerge.Execute(new string[] { "NegativeValue1", "NegativeValue2", "CurrencyValue1", "CurrencyValue2" },
                    new object[] { -1234.25, -1.25, 1234.25, 1.25 });

document.Save(MyDir + "Test-MergeOutput.docx", Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Docx));
1 Like

Thank you,
This solution is working for French Locale now.

@Rakesh2013

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.