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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:23:01+00:00 2026-05-23T01:23:01+00:00

I have a string value that could contain a double, integer, ascii or byte

  • 0

I have a string value that could contain a double, integer, ascii or byte value and I put that value into a JLabel. I would like for the double and long values to be in the form of 4000000000000 instead of the java JLabel default printing style of 4.0E12. Now I know what data type is in the string but I don’t know how to make the JLabel display only non-scientific forms for the double and integer values.

Here is what I tried so far:

String str = value; // string that holds the value

switch (var) // var that says which data type my str is
{
  case LONG:
  //convert my string from scientific to non-scientific here
  break;
  case DOUBLE:
  //convert my string from scientific to non-scientific here
  break;
  case ASCII:
  //do nothing
  break;
  ...
}

JLabel label = new JLabel();
label.setText(str); //Want this to be in non-scientific form

but this method still only prints the scientific form.

Edit:

My conversion looks like:

str = new DecimalFormat("#0.###").format(str);

also yes it is a long value, i left out some of the data type variables for clearity.
I dont know if this will work for every case though even if i do get it working. I need it to work for integer, long, xtended, double and float.

  • 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-23T01:23:02+00:00Added an answer on May 23, 2026 at 1:23 am

    You must be using a different JLabel because it doesn’t do any conversion by default

    JFrame frame = new JFrame();
    JLabel label = new JLabel();
    DecimalFormat df = new DecimalFormat("#0.###");
    label.setText(df.format(4e12));
    frame.add(label);
    frame.pack();
    frame.setVisible(true);
    

    Displays a window with

    4000000000000
    

    I just get the following with that conversion

    DecimalFormat df = new DecimalFormat("#0.###");
    System.out.println(df.format(400000000));
    System.out.println(df.format(4000000000000L));
    System.out.println(df.format(4e12f));
    System.out.println(df.format(4e12));
    

    prints

    400000000
    4000000000000
    3999999983616   <- due to float rounding error.
    4000000000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string value that I want to write to the registry as
Lets say I have a string COLIN. The numeric value of this string would
I have a variable of type Hashmap <String,Integer >. In this, the Integer value
I have a string of values separated by a space that I return to
I have an application which takes a string value of the form %programfiles%\directory\tool.exe from
I have a string which holds a decimal value in it and I need
I often have to convert a retreived value (usually as a string) - and
Spring: In my context.xml, I have: <util:set id=someIDs set-class=java.util.HashSet value-type=java.lang.String> <value>W000000001</value> <value>W000000003</value> <value>W000000009</value> </util:set>
If I have a set number of String 's that I want to check
I have to replace the content of this xml string through java <My:tag>value_1 22&#xA;value_2

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.