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

  • Home
  • SEARCH
  • 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 8161389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:29:22+00:00 2026-06-06T18:29:22+00:00

I want to parse an integer accurately, one that has been potentially formatted according

  • 0

I want to parse an integer accurately, one that has been potentially formatted according to the current locale. If I didn’t parse the integer accurately, I want to know it. So I use:

String string = "1111122222333334444455555";
Locale locale = Locale.getDefault();
NumberFormat numberFormat = NumberFormat.getIntegerInstance(locale);
numberFormat.setParseIntegerOnly();
Number number = numberFormat.parse(string);

Obviously "1111122222333334444455555" represents a big number, bigger than a Long can handle. So NumberFormat gives me… a Double??

I guess I would have expected to receive a BigInteger rather than a Double, especially since I asked for an integer-specific number formatter. But never mind that; the bigger problem is that the double value I get back is 1.1111222223333344E24! This is not equal to 1111122222333334444455555!!

If NumberFormat gives me a parsed value that does not equal that stored in the input string, how do I detect that?

Put another way: “How can I know if the Double value I get back from NumberFormat is exactly equivalent to the integral value represented in the original string?”

  • 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-06-06T18:29:24+00:00Added an answer on June 6, 2026 at 6:29 pm

    The javadocs for parse() state that it will return a Long if possible, otherwise it will return a Double. So just check that the return value is a Long.

    “Returns a Long if possible (e.g., within the range [Long.MIN_VALUE, Long.MAX_VALUE] and with no decimals), otherwise a Double.”

    “How can I know if the Double value I get back from NumberFormat is exactly equivalent to the integral value represented in the original string?”

    If it returns a Double, then it is not exactly equivalent to your integral value because a Double cannot accurately represent values at that magnitude. Concrete example:

      Number a = numberFormat.parse("-9223372036854775809"); // Integer.MIN_VALUE - 1
      Number b = numberFormat.parse("-9223372036854775810"); // Integer.MIN_VALUE - 2
      System.out.println((a.equals(b))); // prints "true"
      Number c = numberFormat.parse("-9223372036854776800");
      System.out.println((a.equals(c))); // prints "true"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse an integer that is unpack() ed using the struct module
I want to parse out each modified file that is reported during FCIV's verification
I am having one XML file and I want to parse only useful data
I have a problem parsing integer & hex numbers. I want to parse C++
I just want to know if there's a better solution to parse a number
I have a string that looks like L\4\ and want to parse it into
Hy! I want to parse a String to a Integer. The String is like
I want to translate/hydrate/expand/parse a comma-separated string of integers and hyhenated integer range expressions
I am having one xml file and I want to parse it to get
I've made a little forum and I want parse the date on newest posts

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.