On Tuesday, 18 April 2000 at 03:00:00 UTC-4, Yun Mo wrote:
With the format "##0.##E00" and method of myformat, I got:
a=0.01 formatted=+1E-03
a=-100600.0 formatted=-100.6E+03
a=-100500.0 formatted=-100.5E+03
a=-100510.0 formatted=-100.51E+03
a=-100500.0000000001 formatted=-100.5E+03
a=0.0 formatted= 0E+00
a=-1230.0 formatted=-1.23E+03
a=99999.99951 formatted=+1E+03
b=100000 formatted=+1E+03
With "0.00E00" and the method of myformat, I obtained:
a=0.01 formatted=+1.00E-02
a=-100600.0 formatted=-1.01E+05
a=-100500.0 formatted=-1.00E+05 (x)
a=-100510.0 formatted=-1.01E+05 (ok)
a=-100500.0000000001 formatted=-1.01E+05 (ok)
a=0.0 formatted= 0.00E+00
a=-1230.0 formatted=-1.23E+03
a=99999.99951 formatted=+1.00E+05
b=100000 formatted=+1.00E+05
It seems that no problem for the fixed decimal format like "0.00E00".
Of course, there exists a worry about formatting 100500 with "0.00E00".
In engineering, we only want some number of valid digits.
The following format is a despoit result. The reason may be that it
takes digit from right side of 100,000.
At lease, the maximum integer digits should larger than 6.
I dont't know the exact reason that it could get the expected result with "0.00E00".
But it can guess that it takes digits from left side of 100,00 for "0.00E00".
java.text.DecimalFormat df = (java.text.DecimalFormat)java.text.NumberFormat.getInstance(); df.setMaximumIntegerDigits(3); System.out.println(df.format(99999.99951));//should at least throw an
//exception, gives 000
Dirk Bosmans wrote:
And don't use java.text.DecimalFormat with exponent notations. Try this one:
java.text.DecimalFormat df = new java.text.DecimalFormat("##0.###E0"); System.out.println(df.format(99999.99951));//should be 100E3, gives 1E3
Dangerous. And what about fixed point? Do you like loosing most-significand digits without a warning?
java.text.DecimalFormat df = (java.text.DecimalFormat)java.text.NumberFormat.getInstance(); df.setMaximumIntegerDigits(3); System.out.println(df.format(99999.99951));//should at least throw an //exception, gives 000
I'm reacting to following parts of Patricia Shanahan <[email protected]>'s article in
comp.lang.java.help on 17 Apr 2000 09:31:08 EDT6
....
. If numbers that happen to be exactly representable in decimal are
. particularly important in your program use BigDecimal instead of double. . Even if double is right for your general arithmetic, if you want a
. different rounding mode from round half even convert to BigDecimal
. before display, use BigDecimal to do the formatting.
.
. Patricia
Greetings,
Dirk Bosmans
http://users.belgacombusiness.net/arci/
- Applicet Framework: turns Applets into Applications
- ArciMath BigDecimal: now with BigDecimalFormat
u a bot and a loser
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)