Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6763855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:31:34+00:00 2026-05-26T14:31:34+00:00

When it comes to parsing numbers with decimal separators from string, Wicket’s BigDecimalConverter behaves

  • 0

When it comes to parsing numbers with decimal separators from string, Wicket’s BigDecimalConverter behaves differently than BigDecimal’s (String val) constructor.

Let’s try to parse a number with comma as the decimal separator using US locale. (I’m using Wicket 1.4.14 BTW.)


new BigDecimalConverter().convertToObject("1,3", Locale.US)
returns 13,


but


Locale.setDefault(Locale.US);
new BigDecimal("1,3")  

throws NumberFormatException.


Why doesn’t BigDecimalConverter behave the same way as BigDecimal in this case? The number “1,3” doesn’t make sense for the US locale.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:31:35+00:00Added an answer on May 26, 2026 at 2:31 pm

    The BigDecimal class implements its own validation algorithm on the input, which is throwing the NumberFormatException.

    The reason why BigDecimalConverter is parsing 1,3 as 13 is that it is using a raw DecimalFormat behind the scenes. In AbstractNumberConverter.parse(), the getNumberFormat(locale) and parse() methods combination boils down to the following snippet, that takes Wicket out of the equation:

    NumberFormat format = NumberFormat.getInstance(Locale.US);
    format.setParseBigDecimal(true);
    BigDecimal bd = format.parseObject("1,3");
    System.out.println(bd.toString()); // Prints 13 !
    

    UPDATE
    The reason why DecimalFormat is ignoring the , character is because it is defined as the grouping separator in the DecimalFormatSymbols for the US locale.
    It is permitted, and legal as it would be in 1,300.5.

    In case you want to avoid converting 1,3 to 13, and throwing a invalid format conversion exception, you could override BigDecimalConverter.getNumberFormat(Locale) in order to modify the DecimalFormat to not use grouping, use a different grouping symbol, or use a more restrictive pattern. For instance:

    TextField<BigDecimal> text = new TextField<BigDecimal>(id, model){
        @Override
        public IConverter getConverter(Class<?> type) {
            return new BigDecimalConverter() {
                @Override
                public NumberFormat getNumberFormat(Locale locale) {
                    NumberFormat format = super.getNumberFormat(locale);
                    format.setGroupingUsed(false);
                    return format;
                }
            };
        }
    };
    text.setType(BigDecimal.class);
    

    Note: Use the above example with caution, create a class for the Converter so it doesn’t get instantiated at each call of getConverter() and don’t modify the NumberFormat instance BigDecimalConverter.getNumberFormat() returns, it might be a global shared instance.

    Just to add, this is the exact piece of code that’s ignoring the , character for being a group separator: DecimalFormat.subparse() branch in line 1522. With input of 1,3, the comma is ignored, being isGroupingUsed() true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that the choice to use string parsing vs. regular expressions comes up
I'll need to accept a string of 5 numbers from the user (only 5).
I'm passing a date from Ruby to Javascript via JSON. It comes into Javascript
It comes up from time to time and I'm wondering of it's possible to
I'm passing as parameter an id to a javascript function, because it comes from
I am trying to get a decimal input from the keyboard, and it is
I'm parsing an existing HTML table on a webpage into an array of numbers
Rails comes with a handy session hash into which we can cram stuff to
Django comes with CSRF protection middleware , which generates a unique per-session token for
Rails comes with RESTful resources out of the box, but do you use those

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.