如何将双精度值添加到 pdfpcell
how to add double value to pdfpcell
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);
}
总计是双精度值,段落构造器不接受双精度值。
那么如何在 pdfpcell
中插入双精度值
尝试String.valueOf
cell4 = new PdfPCell(new Paragraph(String.valueOf(total)));
String.valueOf(double)
returns 双参数的字符串表示。请参阅 official documentation 了解更多信息。
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);
}
总计是双精度值,段落构造器不接受双精度值。 那么如何在 pdfpcell
中插入双精度值尝试String.valueOf
cell4 = new PdfPCell(new Paragraph(String.valueOf(total)));
String.valueOf(double)
returns 双参数的字符串表示。请参阅 official documentation 了解更多信息。