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 7193703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:13:25+00:00 2026-05-28T20:13:25+00:00

I am having trouble with large numbers in java while trying to store them

  • 0

I am having trouble with large numbers in java while trying to store them in float variable.

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class testConversion {


public static void main(String[] args) {

    String s = "135598877.50";

    Float f = Float.parseFloat(s);

    DecimalFormat df = new DecimalFormat("#0.00");

    System.out.println(f);
    System.out.println(df.format(f));

}

}

OUTPUT:

1.3559888E8

135598880.00

The output of this program is 135598880.00 and not 135598877.50.

Why this thing is happening and what is the best way of handling this? I don’t want truncation/rounding at all.

Regards,
Kaddy

  • 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-28T20:13:26+00:00Added an answer on May 28, 2026 at 8:13 pm

    floats are stored using IEE 754. They cannot store large numbers precisely.

    As you hinted in the question, you need to use BigDecimal.

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

Sidebar

Related Questions

Having trouble with a couple of display issues in IE7. Firstly, my large text
I'm working on a fairly large site and am having trouble managing z-indexes. Is
Having no end of trouble including a large landscape pdf in a portrait .tex
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I am having trouble searching a large directory of files for a string. The
I'm having trouble getting a decent query time out of a large MySQL table,
I am having some trouble populating a large plist into an array. Here is
I am having real trouble trying to get decent answers to my questions from
I'm having trouble incorporating a bit of logic into a large SQL query. I'm
I'm having a bit of trouble trying to get this quicksort algorithm to work

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.