Reputation: 1409
Goodmorning, I'm parsing a string to a big decimal but the debugger returns an error when i set the pattern ans simbols to it. The code is very simple and i've taken it from the documentation and from an other post here on stackoverflow which i don't remember what address it is. It is below:
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setGroupingSeparator('.');
symbols.setDecimalSeparator(',');
String pattern = "#.##0,0#";
DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols);
decimalFormat.setParseBigDecimal(true);
(BigDecimal) decimalFormat.parse(entity.getQta()))
the error is thrown at this line:
DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols);
StackTrace of GWT debugger:
com.smartgwt.client.core.JsObject$SGWT_WARN:
09:29:12.673:MOU6:WARN:RPCManager:ATTENZIONE: si e' verificato un errore imprevisto [SC: 500]undefined - response: {clientContext: Obj,
status: -1,
invalidateCache: true,
data: "ATTENZIONE: si e' verificato un errore i..."[59],
internalClientContext: Obj,
context: undef,
startRow: 0,
endRow: 0,
totalRows: 0} at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at
java.lang.reflect.Constructor.newInstance(Constructor.java:422) at
com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105) at
com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at
com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at
com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338) at
com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219) at
com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576) at
com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:304) at
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107) at com.smartgwt.client.data.DataSource.processResponse(DataSource.java) at
com.sgss.common.client.ds.SgssGwtRpcDataSource.handleFailure(SgssGwtRpcDataSource.java:205) at
com.sgss.common.client.ds.SgssGwtRpcDataSource$GenericAsyncCallback.onFailure(SgssGwtRpcDataSource.java:148) at
com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:237) at
com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:259) at
com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412) at sun.reflect.GeneratedMethodAccessor417.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at
com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at
com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at
com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at
com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338) at
com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219) at
com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576) at
com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284) at
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.google.gwt.core.client.impl.Impl.apply(Impl.java) at
com.google.gwt.core.client.impl.Impl.entry0(Impl.java:356) at
sun.reflect.GeneratedMethodAccessor412.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at
com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at
com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at
com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at
com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293) at
com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547) at
com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364) at java.lang.Thread.run(Thread.java:745)
EDIT:I didn't metioned GWT (SMartGwt in my case, cause i'm doing this parsing in the backend, which doesn't use smartgwt but only spring and hibernate.
Upvotes: 1
Views: 1221
Reputation: 3275
Your pattern is incorrect, in the line:
String pattern = "#.##0,0#";
according to the documentation https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html (in the section titled Special Pattern Characters) the "," sign in the pattern is reserves for the grouping separator - not literally the comma in the number; the "." is reserved for the decimal separator, not literally the point character.
Since your numbers are in the format 1.743.711,67 (and not 1,743,711.67), you used the symbols variable to designate "," as the decimal separator and the "." as the grouping separator. However, the pattern doesn't follow the same logic. It swaps the locations of the grouping and decimal separators so it fails.
I would suggest you try:
String pattern = "#,##0.0#";
With the same code and see if it helps.
Upvotes: 2