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.
You must be using a different JLabel because it doesn’t do any conversion by default
Displays a window with
I just get the following with that conversion
prints