首页 文章

如何为pdfpcell添加double值

提问于
浏览
-2
PdfPTable table = new PdfPTable(4); // 4 columns.

        PdfPCell cell1 = new PdfPCell(new Paragraph("Medicine Name"));
        PdfPCell cell2 = new PdfPCell(new Paragraph("Quantity"));
        PdfPCell cell3 = new PdfPCell(new Paragraph("Price"));
        PdfPCell cell4 = new PdfPCell(new Paragraph("Total"));
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        table.addCell(cell4);

         while(rs.next())   // fetch & writing records in pdf files
        {
            quan=rs.getInt("quantity");
            pric=rs.getDouble("price");
            total=quan*pric;


            cell1 = new PdfPCell(new Paragraph(rs.getString("prodt_name")));
            cell2 = new PdfPCell(new Paragraph(quan));
            cell3 = new PdfPCell(new Paragraph(rs.getString("price")));
            cell4 = new PdfPCell(new Paragraph(total));
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        table.addCell(cell4);

        }

total是double值,Paragraph consturctor不接受double值 . 那么如何在pdfpcell中插入double值

1 回答

  • 1

    试试 String.valueOf

    cell4 = new PdfPCell(new Paragraph(String.valueOf(total)));
    

    String.valueOf(double) 返回double参数的字符串表示形式 . 有关更多信息,请参阅official documentation .

相关问题