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)