node.js – Fractional part in float number dont show properly in crosstable component in jaspersoft

I have a task to generate PDFs with nodeJS, so i am working with the node-jasper library.

I want to display a table component that contains float numbers but when i send dataset from back-end, it shows only the integer part of the numbers. Here is my nodjs code:


const express = require('express')

const app = express()
const port = 5000


var jasper = require('node-jasper')({
  path: './lib/jasperreports-6.10.0',
  reports: {
    report: {
      jasper: './jasperFiles/table.jasper',
      jrxml: './jrxmlFiles/table.jrxml',
      conn: 'in_memory_json'
    }
  },
});


app.get('/get_table', (req, res) => {

  var report = {
    report: 'report',
    data: {
      list: jasper.toJsonDataSource(
        {
          data: [
            {
              id: 1,
              val: 2.55
            },
            {
              id: 2,
              val: 3.85
            }
          ]
        },
        'data'
      ),
    }
    ,
    dataset: {}

  }
  var pdf = jasper.pdf(report);
  res.set({
    'Content-type': 'application/pdf',
    'Content-Length': pdf.length
  });
  res.send(pdf)
});

app.listen(port, () => {
  console.log('app is runing on port: ', port)
})

here is my jrxml file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.10.0.final using JasperReports Library version 6.10.0-unknown  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="table" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ea493b18-9fb4-4bab-bdfd-323454e90b99">
    <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Dataset1" uuid="586aa694-4896-425f-b58c-8fceeeb4d3f0">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="val" class="java.lang.Double"/>
        <field name="id" class="java.lang.Integer"/>
    </subDataset>
    <parameter name="list" class="net.sf.jasperreports.engine.JRDataSource"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="274" splitType="Stretch">
            <componentElement>
                <reportElement x="110" y="20" width="200" height="200" uuid="e63d85ed-faa4-4983-a00b-35c18d4e34bf">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                    <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
                    <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
                    <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
                </reportElement>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="Dataset1" uuid="b4c72650-c463-434c-9f7a-c34037079fd7">
                        <dataSourceExpression><![CDATA[$P{list}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="100" uuid="84d356bb-f8fd-4276-8902-42df76c454ec">
                        <jr:tableHeader style="Table_TH" height="30"/>
                        <jr:tableFooter style="Table_TH" height="30"/>
                        <jr:columnHeader style="Table_CH" height="30">
                            <staticText>
                                <reportElement x="0" y="0" width="100" height="30" uuid="7e3d4e8d-23ff-4ecc-b0d4-0081e04262f9"/>
                                <text><![CDATA[val]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:columnFooter style="Table_CH" height="30"/>
                        <jr:detailCell style="Table_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="30" uuid="1392a46d-0fd3-451f-9886-09bbf77894cf"/>
                                <textFieldExpression><![CDATA[$F{val}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="100" uuid="d86214ca-1b51-41fd-a7dd-41c2309a99dc">
                        <jr:tableHeader style="Table_TH" height="30"/>
                        <jr:tableFooter style="Table_TH" height="30"/>
                        <jr:columnHeader style="Table_CH" height="30">
                            <staticText>
                                <reportElement x="0" y="0" width="100" height="30" uuid="b22794ae-8852-41f7-9e9c-366c15efa91b"/>
                                <text><![CDATAhttps://stackoverflow.com/q/73011846]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:columnFooter style="Table_CH" height="30"/>
                        <jr:detailCell style="Table_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="30" uuid="720d1524-19cc-473a-9620-083a9575ac47"/>
                                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

Here is the resulting report: generated rapport

I set double type to ‘val’ column. But as you can see the ‘val’ column contain the numbers with 0 in the fractional part.

Leave a Comment