Decimal formatting


    Sponsored Links


  • 1. how to concect the c++ client with the java file server.
    Hi Friends, Well I am facing a problem. The problem is how to concect the c++ client with the java file server. I am using mico as orb for mapping idl to c++. But how do I proceed further. Please give me a detailed information or link or code. Thanks With Regards.
  • 2. =?utf-8?B?5L+C6aaZ5riv5LiA6ZaTSVTlhazlj7gs5Y+rQWR2YW5jZWQgVGVsZXNvZnQsIOacieWAi2Fw5Y+rRGFuLA==?=
    T,dvanced Telesoft, €pan, , €, ". , €, €. , , € IT orward
  • 3. JStudio Creator class not found org.apache.catalina.realm.JNDIRealm.
    in my server.xml file i have this Realm configuration: <Realm className="org.apache.catalina.realm.JNDIRealm " debug="99" connectionURL="ldap://" referrals="follow" userBase="cn=Users,dc=eystest,dc=local" userSearch="(sAMAccountName={0})" userSubtree="true" userRoleName="Users" roleBase="cn=Users,dc=eystest,dc=local" roleSearch="(sAMAccountName={0})" roleSubtree="true" rolename="cn" /> but when try to run the tomcat server i got this exception: Sep 6, 2006 1:46:50 PM org.apache.tomcat.util.digester.Digester startElement SEVERE: Begin event threw exception java.lang.ClassNotFoundException: org.apache.catalina.realm.JNDIRealm at$ at Method) at at java.lang.ClassLoader.loadClass( i can't find the org.apache.catalina.realm.JNDIRealm class. can any one help this dumber.!!. thanks in advance.
  • 4. Dealing with Degrees and Radians
    Hello, I'm trying to determine the length of the opposite leg of a triangle using the Math.tan() function. However it seems Math is set in radians (at least, I'm getting negative numbers returned from tangent, and I belive that's not possible in degrees) and I can't figure out how to tell it to run in degrees. I tried using Math.toDegrees() but I still receive strange/negative numbers for tangent. Anyone know how to change this setting?

Decimal formatting

Postby Rob McDonald » Thu, 15 Dec 2005 00:53:37 GMT

I'm familiar with java.text.DecimalFormat it stinks.

I need to format a double to fit into a certain sized space in a display.
Unfortunately, I don't know the magnitude of the number.  Sometimes it may
be very small, O(1e-6), other times, O(1), and sometimes very large O(1e6).

What I need is a way to specify the overall width of the formatted number.
Or possibly the number of significant digits.

That way, It will be smart enough to format the following numbers in a sane
manner (as shown)....


The problem with DecimalFormat and the other Java solutions I've found is
that they ask you to explicitly define the numeric format, you can't just
specify the width or precision.

In C, what I'd like to do is "% 5.3g"   The g switches between fixed and
scientific notation.

Fortran also has a similar expression.

Any help is appreciated,


Re: Decimal formatting

Postby Boudewijn Dijkstra » Thu, 15 Dec 2005 01:57:50 GMT

"Rob McDonald" < XXXX@XXXXX.COM > schreef in bericht 

Have you tried String.format("%5.3g", d) ? 

Re: Decimal formatting

Postby Mark Thomas » Thu, 15 Dec 2005 02:16:44 GMT


java.util.Formatter has the ability to do what you want, as has the 
method printf() - a method of PrintWriter & PrintStream since Java 1.5


Re: Decimal formatting

Postby Rob McDonald » Thu, 15 Dec 2005 02:29:22 GMT

> > I'm familiar with java.text.DecimalFormat it stinks.

Thanks for the tip,

String.format("%10.4g", d)

Worked nicely for what I wanted.  It would be nice if one could abbreviate
the exponent in the scientific notation, but I'll take it (i.e. 1.23e+04
would be prettier written as 1.23e4).



Similar Threads:

1.Decimal Format

I am trying to convert a double value to two decimal places, but when I
enter an amount say 12345678.99000, I get the result as 12345678.99E7
instead of 12345678.99.
Here is what my code looks like....

     DecimalFormat df = new DecimalFormat("##############0.00");
        boolean appendO = false;
        StringBuffer buff = new StringBuffer();
        Double amt = new Double(df.format(amount));
        String sAmount = amt.toString();
        String a = sAmount.replace(',',' ');
        StringTokenizer tok = new StringTokenizer(a,".");
        while (tok.hasMoreTokens())
            String token1 = tok.nextToken();
            String token2 = tok.nextToken();
            if (token2.length()<2)
                appendO = true;



2.decimal format, how to not round


Pls look at the following:

        DecimalFormat format = new DecimalFormat("#,###.00");

        System.out.println(format.format(1234.999)); // 1,235.00

I'm wondering, how to make it NOT round?

3.JTextField and decimal format...

Hi how to work with decimals in JTextField. I have a following problem...

For example I want to make a generic class which will take input from
Requrements are :
1) input : +-0123456789E and .(decimal point)
2) + or - can be inputed as a first digit
3) .(decimal point) can be inputed only once
4) E means exponent value 1E2 = 100, after E + or - can be inputed and
integer value after that
5) decimal format can be with and without E, E-style can be forbidden
6) at this component number of digits after .(decimal point) can be set.
    (after that it is not possible to input digits..)

I have worked 1) - 3) but I have a feeling that there is some generic class
in Java API. If there ain`t no, perhaps I can use some tested "open source
Any help welcome!

Best regards

4.decimal formatting

5.decimal formatting (Java solution)

6. Money Format + Decimal Place Format

7. Formatting a long decimal into Gb, Mb, or Kb (using String.format)

8. Need Help with Final Project which involves an "Equals" Method, a "copy" method, and a Decimal Format Class

Return to JAVA


Who is online

Users browsing this forum: No registered users and 96 guest