I encounter some weird rounding issue in JSF using below JSF code as numbers don't add up correctly:
<h:outputLabel value="Subtotal"/><h:outputText value="#{shoppingCart.itemsPrice}"><f:convertNumber groupingUsed="true" type="currency" currencySymbol="€"/></h:outputText>
<h:outputLabel value="Shipping"/><h:outputText value="#{shoppingCart.shippingPrice}"><f:convertNumber groupingUsed="true" type="currency" currencySymbol="€"/></h:outputText>
<h:outputLabel value="Vfat"/><h:outputText value="#{shoppingCart.vfat}"><f:convertNumber groupingUsed="true" type="currency" currencySymbol="€"/></h:outputText>
<h:outputLabel value="Total"/><h:outputText value="#{shoppingCart.totalGrossPrice}"><f:convertNumber groupingUsed="true" type="currency" currencySymbol="€"/></h:outputText>
here the numbers in question
- Subtotal €49.50
- Shipping €0.00
- Vfat €9.40
- Total €58.91
These numbers are not quite right sine VFAT in my country is 19% and thus VFat is actually 9,405 which I validated to be the value that is calculated. Displayed it should be 9,41 but it shows only 9,40 above. Even weirder however is that adding 49,50 to it gives the right 49,50+9,405 = 58,91 (rounded for display). So obviously this would be very confusing for a customer where the missing cent comes from. Obviously there may be cases where this cannot be avoided e.g. Vfat is ?,006 and ItemPrice is ?,004 then summed up this ?,01 but these is not even the case here.
Any ideas?