Transform String to Number when Building Report from Template Word Document using LINQ Reporting Engine C# | Json Convert Serialize Object

Template:

Result:

Code:

var document = new Document(@"D:\template.docx");

var jsonString = JsonConvert.SerializeObject(new
{
    Data = new
    {
        Price1 = 4.4000M,
        Price2 = "4.0001",
        Price3 = "4.0000"
    }
});

var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
var jsonDataSource = new JsonDataSource(jsonStream);

var engine = new ReportingEngine();
engine.BuildReport(document, jsonDataSource);
document.Save(@"D:\result.pdf");

In the template, I set the format of the numbers to “#,##0,00” so that they are displayed to 2 decimal places. This is what I get:

Price 1: 4.40
Price 2: 4.00
Price 3: -2,147,483,648.00

The value of Price 3 is weird. This problem occurs with data that is of type string and whose all numbers after the decimal point are zeros (e.g. 40.0, 51.00, 52.0000). It will work well if Price3 is of C# decimal type. However, the point is, I’m not allowed to modify the code, but only the template.

Why does it happen and how can I fix this? Thanks.

result.pdf (43.5 KB)

@RyanNguyen,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of any correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-20292. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Hi @awais.hafeez, it’s now 12 days. Can i have any update from Aspose team?

@lukasnguyen,

We have good news for you i.e. WORDSNET-20292 has now been resolved. The fix of this issue will be included in the 20.5 (next version) of Aspose.Words. We will inform you via this thread as soon as the next version containing the fix of this issue will be released during the next week.

Hi @awais.hafeez, noted. Thanks.

@lukasnguyen,

The 20.5 version of Aspose.Words for .NET API is now available and you can upgrade to the latest version from the following links:

1 Like

The issues you have found earlier (filed as WORDSNET-20292) have been fixed in this Aspose.Words for .NET 20.5 update and this Aspose.Words for Java 20.5 update.