I'm using Spring 3 with JPA.
I've got my Product class like this:
@Entity
@Table(name="products")
public class Product {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
@Column(name="price", precision=12, scale=2)
private BigDecimal price;
The problem is that when I fill my Product creation form with a price like "1.20" I get in my views "1.2". The trailing zero disappears.
How can I solve this problem?
You can use the JSTL format taglib to format the display of a BigDecimal.
To format a BigDecimal include a Product as an attribute and reference the price field via the instance of Product using JSP EL.
<fmt:formatNumber value="${product.price }" minFractionDigits="2"/>
You should also include the JSTL FMT taglib:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
And will need to place the JSTL API & Implementation Jars on your classpath:
Jar Files
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With