I am working with a datasource in JSON format:
{
"account": {
"balance": 5500,
"cashback": -999900499999999999
}
}
I am using the following template syntax:
<<[account.balance + account.cashback]>>
Original Output: -9.999004999999945E+17
Expected Output: -999900499999994499
It seems the calculation is returning the result in scientific notation. Is it possible to update the reporting engine in a way that it gives the actual answer in the standard numeric format instead of scientific notation?
@abhishekouta
The issue you’re encountering with the calculation returning results in scientific notation is a common one when dealing with large or small numbers in programming. Unfortunately, the LINQ Reporting Engine does not provide a built-in way to format numbers directly within the template syntax to avoid scientific notation.
However, you can handle this by converting the result to a string with a specific format in your code before passing it to the template. Here’s a workaround you can implement:
-
Modify the Calculation: Instead of performing the calculation directly in the template, you can calculate the result in your code and format it as a string.
-
Use String Formatting: You can format the number to ensure it appears in standard numeric format. For example, in C#, you can use ToString("F0")
to format the number without decimal places.
Here’s an example of how you might implement this in C#:
using Aspose.Words;
using Aspose.Words.Reporting;
// Your JSON data
var jsonData = new {
account = new {
balance = 5500,
cashback = -999900499999999999
}
};
// Calculate the result
decimal result = jsonData.account.balance + jsonData.account.cashback;
// Format the result as a string
string formattedResult = result.ToString("F0");
// Now use this formatted result in your template
Document doc = new Document("template.docx");
doc.MailMerge.Execute(new[] { "result" }, new[] { formattedResult });
doc.Save("output.docx");
In this example, the result
is calculated in the code, formatted to avoid scientific notation, and then passed to the template for rendering. This way, you can ensure that the output is in the desired numeric format.
If you need further assistance or have additional questions, feel free to ask!
this tags are dynamic, just handling specific key is not efficient solution.
could anyone help me on this?
@abhishekouta Unfortunately, I cannot reproduce the problem on my side using the latest 25.3 version of Aspose.Words and the following code:
JsonDataSource ds = new JsonDataSource(@"C:\Temp\data.json");
Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, ds, "account");
doc.Save(@"C:\Temp\out.docx");
data.zip (224 Bytes)
in.docx (13.9 KB)
out.docx (11.2 KB)