wood burning stoves 2.0*
The moose likes Java in General and the fly likes amount currency datatype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

amount currency datatype

Rajni Patel
Ranch Hand

Joined: Sep 03, 2009
Posts: 84
Hi,

I have use double datatype for transaction amount field. If i enter 9999999.99 then it is ok but if i enter more then this no. then it give me infinite number. so when i save then i am validating this amount and in validate method, i am checking if value contains 0-9 or . then return true or false. so in validate method it give error if amount is more then 9999999.99.

Please any body can guide me, how can i solve this problem.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61448
    
  67

Using a double to store currency will give you no end of troubles as it loses accuracy too easily.

More info: Java currency


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajni Patel
Ranch Hand

Joined: Sep 03, 2009
Posts: 84
can I use String?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61448
    
  67

String?

Read the articles in the link.

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11441
    
  16

Rajni Patel wrote:can I use String?

yes. But that would be a Really Bad Idea(tm).


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rajni Patel
Ranch Hand

Joined: Sep 03, 2009
Posts: 84
I have used BigDecimal. But now when I enter String value for Ex: "dsfdsf" then below error is coming. I am using struts1.1. when i click on save then even its not going in validate method in form. Please advice.

Thanks.



Error 500--Internal Server Error
javax.servlet.ServletException: BeanUtils.populate
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:475)
at org.apache.struts.chain.commands.servlet.PopulateActionForm.populate(PopulateActionForm.java:50)
at org.apache.struts.chain.commands.AbstractPopulateActionForm.execute(AbstractPopulateActionForm.java:60)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at com.cibc.ibcs.fmca.was.filter.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:46)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: org.apache.commons.beanutils.ConversionException: Error converting from 'String' to 'BigDecimal' null
at org.apache.commons.beanutils.converters.AbstractConverter.handleError(AbstractConverter.java:267)
at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:164)
at org.apache.commons.beanutils.converters.ConverterFacade.convert(ConverterFacade.java:60)
at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:470)
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1006)
at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:830)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:433)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:473)
... 26 more
Caused by: java.lang.NumberFormatException
at java.math.BigDecimal.(BigDecimal.java:368)
at java.math.BigDecimal.(BigDecimal.java:647)
at org.apache.commons.beanutils.converters.NumberConverter.toNumber(NumberConverter.java:448)
at org.apache.commons.beanutils.converters.NumberConverter.convertToType(NumberConverter.java:268)
at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:156)
... 32 more

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61448
    
  67

Please post your Struts problem in the Struts forum.

I've closed this post to prevent redundant conversations on the Struts issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: amount currency datatype